开始之前
这个是用来记录在vps装mysql的过程,前前后后折腾了两天,比较痛苦,中途安装失败重装了几次,因为用的是国外的官网下载,因此加了代理服务,下载速度5MB/s,妥妥的
准备工作
安装之前需要检查当前服务器环境是否安装了Mariadb,一般情况下,系统会默认装了Mariadb
1 | rpm -qa | grep mariadb |
得到如下结果
1 | mariadb-5.5.56-2.el7.x86_64 |
输入一下代码,一一卸载,不同版本启动服务容易产生冲突
1 | rpm -e --nodeps mariadb-5.5.56-2.el7.x86_64 mariadb-devel-5.5.56-2.el7.x86_64 mariadb-libs-5.5.56-2.el7.x86_64 mariadb-server-5.5.56-2.el7.x86_64 |
进入root目录(也可以其他目录,下载存放的文件夹)
1 | cd /root |
下载安装
1 | wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz |
解压至/usr/local/目录下
1 | tar -xzvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ |
cd到/usr/local目录,把解压的数据库默认名字换一换
1 | cd /usr/local |
检查库文件是否有删除,若有便删除(linux系统自带的)
1 | [root@host mysql] |
检查mysql组和用户是否存在,如无创建
1 | [root@host~]# cat /etc/group | grep mysql |
建立一个mysql的组
1 | [root@host~] |
建立mysql用户,并且把用户放到mysql组
1 | [root@host~] |
如果有输入删除原来用户和组
1 | userdel mysql |
这里的mysql是用户名字,当初建立组的时候设定
cd到mysql文件夹
创建mysql组和mysql用户
1 | [root@host~] |
在 mysql 文件下添加 data 目录
1 | [root@host mysql] |
更改mysql目录下所有的目录及文件夹所属组合用户
1 | cd /usr/local/ |
初始化
进入/mysql/bin文件夹,初始化数据库
1 | [root@host bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/--datadir=/usr/local/mysql/data/ |
初始化中出现 error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory的错误,如图所示
这里需要libais包,可以解决办法
1 | [root@host bin] |
注意,为了预防其他事件出现,建议把环境改成英文,以后系统最好也用原版英文不会有语言兼容而报错,输入下面代码
1 | [root@dbserver bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US |
在执行一次,出现下面结果,注意,记住最后数据库的初始密码
1 | 2018-08-21T14:56:56.679269Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). |
配置my.cnf
进入 /usr/local/mysql/support-files/ 目录下,查看是否存在my-default.cnf 文件,如果存在直接 copy 到 /etc/my.cnf 文件中
1 | cp -a ./support-files/my-default.cnf /etc/my.cnf |
如果不存在 my-default.cnf 文件, 则在 /etc/ 目录下创建 my.cnf
1 | cd /etc/ |
输入以下内容
1 | \#[mysql] |
启动服务
1 | [root@host mysql] |
如图所示
将mysqld服务加入VPS开机自启动项
将{mysql}/ support-files/mysql.server 拷贝为/etc/init.d/mysql并设置运行权限,这样就可以使用service mysql命令启动/停止服务,
否则就只能使用{mysql}/bin/mysqld_safe &命令来启动服务
还需要把mysql.server中basedir的相关路径,改为自定义的路径,默认路径是/usr/local/mysql
1 | [root@host bin]# cd ../support-files [root@host support-files]# cp mysql.server /etc/init.d/mysql [root@host support-files]# chmod +x /etc/init.d/mysql |
启动服务
1 | cd /usr/local/mysql/bin |
终于搞定了,/(ㄒoㄒ)/~~哭一下
也有可能会出现报错,
出现这样情况解决办法
1 | [ ] |
登录mysql
1 | [root@host bin] |
设置密码,更改为root
1 | mysql> set password=password("root"); |
1 | Query OK, 0 rows affected, 1 warning(0.00sec) |
如果忘记了密码还可以这样操作
1 | [ ] |
设置远程登录权限
1 | mysql> grant all privileges on *.* to'root' @'%' identified by 'root'; |
进程关闭
若以上步骤中出现其他错误,可以看看 mysql 是否关闭了,先关闭端口,然后在试试
1 | [root@host ~] |
1 | [root@host ~] |
如果netstat功能无法实现,需要执行下面的语句
1 | yum install net-tools |
就能解决问题
写在后面的话
Navicat连接vps mysql
Navicat在v12以下是不能连上服务器的mysql,本地的可以,解决办法,只要升级Navicat premium版本到v12.0以上就可以连接成功
参考:
https://blog.csdn.net/zhou920786312/article/details/77750604