[root@mysql3 percona-server-5.7.23-24]# mkdir -p /opt/mysql57
[root@mysql3 percona-server-5.7.23-24]# mkdir -p /data/mysql57/data
#编译的时候加上with_debug
cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql57 -DMYSQL_DATADIR=/data/mysql57/data -DSYSCONFDIR=/opt/mysql57 -DWITH_BOOST=/usr/local/boost -DWITH_DEBUG=1
#初始化db
[root@mysql3 mysql57]# /opt/mysql57/bin/mysqld --initialize --user=mysql --basedir=/opt/mysql57 --datadir=/data/mysql57/data
[root@mysql3 mysql57]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld3308
启动db
[root@mysql3 mysql57]# /etc/rc.d/init.d/mysqld3308 start
Starting MySQL (Percona Server).... SUCCESS!
[root@mysql3 mysql57]# ps -ef|grep mysqld
root 1354 1 0 Oct28 ? 00:00:00 /bin/sh /opt/mysql/bin/mysqld_safe --datadir=/data/mysql/data --pid-file=/data/mysql/data/mysql3.pid
mysql 2524 1354 0 Oct28 ? 01:31:38 /opt/mysql/bin/mysqld --basedir=/opt/mysql --datadir=/data/mysql/data --plugin-dir=/opt/mysql/lib/mysql/plugin --user=mysql --log-error=/data/mysql/log/alert.log --open-files-limit=135582 --pid-file=/data/mysql/data/mysql3.pid --socket=/data/mysql/run/mysql.sock --port=3306
root 3776 1 0 09:23 pts/3 00:00:00 /bin/sh /opt/mysql57/bin/mysqld_safe --datadir=/data/mysql57/data --pid-file=/data/mysql57/data/mysql3.pid
mysql 4934 3776 22 09:23 pts/3 00:00:03 /opt/mysql57/bin/mysqld --basedir=/opt/mysql57 --datadir=/data/mysql57/data --plugin-dir=/opt/mysql57/lib/mysql/plugin --user=mysql --log-error=/data/mysql57/log/alert.log --open-files-limit=135582 --pid-file=/data/mysql57/data/mysql3.pid --socket=/data/mysql57/run/mysql.sock --port=3308
root 4983 27157 0 09:23 pts/3 00:00:00 grep mysqld
[root@mysql3 mysql57]#
登录db
[root@mysql3 mysql57]# /opt/mysql57/bin/mysql --socket=/data/mysql57/run/mysql.sock
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
忘记了初始化db时的密码,my.cnf中加入skip-grant-tables重启mysqld
[root@mysql3 mysql57]#
[root@mysql3 mysql57]# /etc/rc.d/init.d/mysqld3308 restart
Shutting down MySQL (Percona Server).. SUCCESS!
Starting MySQL (Percona Server).... SUCCESS!
[root@mysql3 mysql57]#
[root@mysql3 mysql57]# /opt/mysql57/bin/mysql --socket=/data/mysql57/run/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23-24-debug-log Source distribution
Copyright (c) 2009-2018 Percona LLC and/or its affiliates
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.
root@(none) 09:27:15>show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
root@(none) 09:27:18>
root@mysql 09:28:28>select user,host,authentication_string from user;
+---------------+-----------+-------------------------------------------+
| user | host | authentication_string |
+---------------+-----------+-------------------------------------------+
| root | localhost | *89C6AA92FB4A025F12E4016BA0A7EDDB685AC1A9 |
| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+---------------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)
root@mysql 09:28:41>alter user root@localhost identified by '';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
root@mysql 09:29:36>update mysql.user set authentication_string=password('xueledba') where user='root' ;
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 1
root@mysql 09:29:49>flush privileges;
Query OK, 0 rows affected (0.00 sec)
注释掉my.cnf中的skip-grant-tables重启mysqld,用设置的新密码登录:
[root@mysql3 mysql57]# /opt/mysql57/bin/mysql --socket=/data/mysql57/run/mysql.sock -pxueledba
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 4
Server version: 5.7.23-24-debug-log
Copyright (c) 2009-2018 Percona LLC and/or its affiliates
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.
(unknown)@(none) 09:31:15>use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
(unknown)@(none) 09:31:30>alter user root@localhost identified by '';
Query OK, 0 rows affected (0.00 sec)
root@(none) 09:31:38>flush privileges;
Query OK, 0 rows affected (0.00 sec)
root@(none) 09:31:43>use mysql;
Database changed
root@mysql 09:31:46>show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
退出再登录,就不需要密码了
[root@mysql3 mysql57]# /opt/mysql57/bin/mysql --socket=/data/mysql57/run/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.23-24-debug-log Source distribution
Copyright (c) 2009-2018 Percona LLC and/or its affiliates
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.
root@(none) 09:32:48>show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
root@(none) 09:32:53>exit
Bye
设置别名:
[root@mysql3 mysql57]# vi ~/.bash_profile
alias mysql2='/opt/mysql57/bin/mysql'
[root@mysql3 mysql57]# source ~/.bash_profile
[root@mysql3 mysql57]# mysql2
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.23-24-debug-log Source distribution
Copyright (c) 2009-2018 Percona LLC and/or its affiliates
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.
root@(none) 09:34:12>exit
Bye