流程八:配置和管理MySQL多实例数据库
1)加入开机自启
[root@localhost 3306]# echo "#mysql multi instances" >> /etc/rc.local
[root@localhost 3306]# echo "/data/3306/mysqld start" >> /etc/rc.local
[root@localhost 3306]# echo "/data/3307/mysqld start" >> /etc/rc.local
2)登录MySQL测试
[root@localhost 3306]# mysql -S /data/3306/mysql.sock #mysql.sock用于区分登录不同的实例
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection> Server version: 5.5.32-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| data |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.01 sec)
mysql> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
3)MySQL多实例数据库的管理方法
无密码情况下登录数据库方法:
mysql -S /data/3306/mysql.sock
mysql -S /data/3307/mysql.sock
重启对应实例数据库的命令:
/data/3306/mysqld restart
4)MySQL安全配置
通过mysqladmin命令为MySQL不同实例的数据库设置独立的密码,命令如下:
[root@localhost 3306]# mysqladmin -u root -S /data/3306/mysql.sock password 'ywxi123'
[root@localhost 3306]# mysqladmin -u root -S /data/3307/mysql.sock password 'ywxi123'
[root@localhost 3306]# mysql -uroot -pywxi123 -S /data/3306/mysql.sock
[root@localhost 3306]# mysql -uroot -pywxi123 -S /data/3307/mysql.sock
5)再增加一个MySQL的实例
mkdir -p /data/3308/data
\cp /data/3306/mysqld /data/3308/
\cp /data/3306/my.cnf /data/3308/
sed -i 's/3306/3308/g' /data/3308/my.cnf
sed -i 's/3306/3308/g' /data/3308/mysqld
chmod 700 /data/3308/mysqld
cd /application/mysql/scripts/
./mysql_install_db --basedir=/application/mysql --datadir=/data/3308 --user=mysql
chown -R mysql:mysql /data/3308/
egrep "server_id|log_bin" /data/3308/my.cnf
/data/3308/mysqld start
netstat -tnlp | grep 3308