手动安装mysql问题汇总

环境
Linux: Centos 7
Mysql: 8.0.16

按照https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html安装mysql后,启动失败,遇到以下问题,一一排查:

*注意!寻找mysql配置文件my.cnf的方式:

$ mysql --help | grep my.cnf

控制台会显示系统读取mysql配置文件的目录,按优先次序排序。

Starting MySQLCouldn’t find MySQL server

运行:

	mysql.server start

报错:

./mysql.server:行239: my_print_defaults: 未找到命令
[mysqld]
Starting MySQLCouldn't find MySQL server (/usr/local/mysql/[失败]sqld_safe)

解决:
因为没有指定mysql安装目录,打开my.cnf,添加配置:

basedir=/usr/local/mysql 
# 根据自己的安装目录配置

The server quit without updating PID file

运行:

mysql.server start

报错:

Starting MySQL.The server quit without updating PID file (/[失败]b/mysql/xxx.pid).

解决:
因为my.cnf配置中的,日志等目录没有创建或者权限不足。打开my.cnf,注意一下目录:

[mysqld]
...
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
...
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
...

如果不存在就创建,并且将用户和组设置成mysql:

$ chown -R mysql:mysql [dir]

/tmp/mysql.sock

运行:

mysql

报错:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

解决:
查看my.cnf中socket的配置:

socket=/var/lib/mysql/mysql.sock

确认该目录下确实存在该文件情况下,创建软链接:

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

你可能感兴趣的:(mysql)