第一步:找到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.pid10 11 # Disabling symbolic-links is recommended to prevent assorted security risks12 symbolic-links=013 # 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 the16 # instructions in http://fedoraproject.org/wiki/Systemd17 18 [client]19 default-character-set=utf8mb420 # default-character-set=utf821 socket=/usr/local/mysql/mysql.sock22 23 [mysql]24 default-character-set=utf8mb425 socket=/usr/local/mysql/mysql.sock26 27 # include all files from the config directory28 #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掉再重启,问题得以解决
参考网址