第一步:找到my.cnf文件。在etc目录下,修改或添加下面三个地方
1 [mysqld] 2 character-set-server=utf8mb4 3 default_password_lifetime=0 4 datadir=/usr/local/mysql/data 5 socket=/usr/local/mysql/mysql.sock 6 7 [mysqld_safe] 8 log-error=/usr/local/mysql/logs/mysqld.log 9 pid-file=/usr/local/mysql/pids/mysqld.pid 10 11 # Disabling symbolic-links is recommended to prevent assorted security risks 12 symbolic-links=0 13 # Settings user and group are ignored when systemd is used. 14 # If you need to run mysqld under a different user or group, 15 # customize your systemd unit file for mariadb according to the 16 # instructions in http://fedoraproject.org/wiki/Systemd 17 18 [client] 19 default-character-set=utf8mb4 20 # default-character-set=utf8 21 socket=/usr/local/mysql/mysql.sock 22 23 [mysql] 24 default-character-set=utf8mb4 25 socket=/usr/local/mysql/mysql.sock 26 27 # include all files from the config directory 28 # 29 !includedir /etc/my.cnf.d
第二步:重启MySQL服务
备注:如果重启发生错误
# ps -aux | grep mysql //查看mysqld服务的端口
一堆东西,显示没什么异常
# netstat -apn | grep 3306 //直接看3306对应端口的情况
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2896/mysqld
找到问题
[root@IM2_JH_OTT mysql-5.7.16]# kill 2896
[root@IM2_JH_OTT mysql-5.7.16]# service mysqld restart
把占用端口的服务2896kill掉再重启,问题得以解决
参考网址