从官网下载linux通用版本tar.gz压缩包
安装过程
-
解压到指定目录
# 解压 tar -zxvf mysql-xxx.tar.gz -C /usr/local #重命名为mysql目录 mv /usr/local/mysql-xxx /usr/local/mysql
-
添加mysql用户组和mysql用户
groupadd mysql # -s /bin/false参数指定mysql用户仅拥有所有权,而没有登录权限 useradd -r -g mysql -s /bin/false mysql #
-
修改当前目录拥有者为新建的mysql用户
cd /usr/local/mysql chown -R mysql:mysql ./
-
安装mysql
# 执行成功后,会显示生成一个临时密码(请copy保存好) ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
-
将mysql进程放入系统进程中
cp support-files/mysql.server /etc/init.d/mysqld
-
启动mysql
service mysqld start
可能遇到的问题
-
运行./bin/mysql -u root -p 输入密码后报以下错误:
Can't connect to local MySQL server through socket '/tmp/mysql.sock'
解决:查找本机mysql.sock所在位置find / -name 'mysql.sock',如在/var/lib/mysql/mysql.sock,然后修改mysql配置文件my.cnf,确保mysqld、client和mysql三段都设置正确的socket路径。
[mysqld] datadir=/usr/local/mysql/data socket=/var/lib/mysql/mysql.sock [client] default-character-set=utf8 socket=/var/lib/mysql/mysql.sock [mysql] default-character-set=utf8 socket=/var/lib/mysql/mysql.sock
-
使用客户端如Navicat、Sequel等连接报错
Connection Failed Be sure that the address is correct and that you have the necessary privileges MySQL said: Can't connect to MySQL server on...
解决: 增加远程连接权限
# 进入mysql, 增加权限 mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION; mysql>FLUSH PRIVILEGES; # 如果还是不能连接,请查看防火墙是否开启,以下是centos的操作命令,其它系统请自行查找对应的命令 systemctl stop firewalld
网友评论