1.进入配置文件/etc/my.conf,添加skip-grant-table:
[root@server ~]# vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
skip-grant-tables
2.重启服务
[root@server ~]# service mysqld restart
Shutting down MySQL.... SUCCESS!
Starting MySQL.. SUCCESS!
3.更新mysql.user表,设置user=root,并且host=localhost的记录中authentication_string的密码
mysql> update mysql.user set authentication_string = password('tjp123') where User = 'root' and Host = 'localhost';
Query OK, 1 row affected, 1 warning (0.36 sec)
Rows matched: 1 Changed: 1 Warnings: 1
4.删除配置文件中的skip-grant-tables重启服务
5.重启服务
[root@server ~]# service mysqld restart
Shutting down MySQL.... SUCCESS!
Starting MySQL.. SUCCESS!
验证
[root@server ~]# mysql -uroot -ptjp123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
创建各实例数据存放的目录
[root@server data]# mkdir -p /opt/data/{3306,3307,3308}
[root@server data]# ls
3306 ib_logfile1 mysql_bin.000016 server.err
3307 ibtmp1 mysql_bin.000017 sys
3308 mysql mysql_bin.000018 tjp
初始化各实例
[root@server ~]# mysqld --initialize --user=mysql --datadir=/opt/data/3306
[root@server ~]# mysqld --initialize --user=mysql --datadir=/opt/data/3307
[root@server ~]# mysqld --initialize --user=mysql --datadir=/opt/data/3308
截取密码
_KhT(H5rR;Cm
kqzAwRO<=0qf
R%>Uehoh=80(
安装perl
[root@server ~]# yum -y install perl
配置配置文件/etc/my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
[mysqld3306]
datadir = /opt/data/3306
port = 3306
socket = /tmp/mysql3306.sock
pid-file = /opt/data/3306/mysql_3306.pid
log-error=/var/log/3306.log
[mysqld3307]
datadir = /opt/data/3307
port = 3307
socket = /tmp/mysql3307.sock
pid-file = /opt/data/3307/mysql_3307.pid
log-error=/var/log/3307.log
[mysqld3308]
datadir = /opt/data/3308
port = 3308
socket = /tmp/mysql3308.sock
pid-file = /opt/data/3308/mysql_3308.pid
log-error=/var/log/3308.log
启动各实例
[root@server ~]# mysqld_multi start 3306
Wide character in print at /usr/local/mysql/bin/mysqld_multi line 672.
[root@server ~]# mysqld_multi start 3307
[root@server ~]# mysqld_multi start 3308
[root@server data]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 80 *:3306 *:*
LISTEN 0 80 *:3307 *:*
LISTEN 0 50 [::]:139 [::]:*
LISTEN 0 80 *:3308 *:*
信息加载中,请等待
微信客服(速回)
微信客服(慢回)