三.Mysql-5.7单独部署
1.修改配置文件,先单独部署5.7。当前已经运行了一个数据库,那将/etc/my.cfn原有配置拷贝的一旁,等后面再用。
cp -p /etc/my.cnf /tmp/my.cnf.bak
原原来的删除,先将5.7初始化再说
vim /etc/my.cnf
-
[mysqld_safe]
-
nice =
-
pid-file =
/data/seven/mysqld.pid
-
[mysqld]
-
bind-address =
0.0.0.0
-
user = mysql
-
basedir =
/usr/local/mysql-5.7
-
datadir =
/data/seven
-
socket =
/data/seven/mysql.sock
-
port =
3307
-
log-error =
/data/seven/mysql.log
2.初始化
/usr/local/mysql-5.7/bin/mysqld --initialize --user=mysql --datadir=/data/seven --basedir=/usr/local/mysql-5.7
没有任何输出就是成功了
四.启动Mysql-5.7
这里将原有的5.6和新的5.7都纳入multi的管理
1.添加多版本控制
vim /etc/my.cnf
-
[mysql]
#客户端
-
default-character-set=utf8mb4
-
[mysqld_multi]
-
#填写任意一个版本的位置就行
-
mysqld =
/usr/local/mysql-5.6/bin/mysqld_safe
-
mysqladmin =
/usr/local/mysql-5.6/bin/mysqladmin
-
#multi的日志
-
log =
/tmp/mysql_multi.log
-
user = multi #在每个账号设置一个账户,有管理权限的,让multi可以控制数据库的关闭重启
-
password = multiadmin
-
#3306这个是原有的配置,这里整个拷贝过来即可
-
[mysqld3306]
-
port =
3306
-
socket=/usr/local/mysql/mysql.sock
-
basedir=/usr/local/mysql
-
datadir=/usr/local/mysql/data
-
max_connection=200
-
character-set-server=utf8
-
default-storage-engine=INNODB
-
lower_case_table_name=1
-
max_allowed_packet=16M
-
log-error=/var/log/mysql/mysql.log
-
pid-file=/var/log/mysql/mysql.pid
-
bind-address =
0.0.0.0
-
#3307的,多加了一个pid-file。
-
[mysqld3307]
-
#跳过密码,因为5.7密码写到日志里了,但这里没看到
-
skip-grant-tables
-
bind-address =
0.0.0.0
-
user = mysql
-
basedir =
/usr/local/mysql-5.7
-
datadir =
/data/seven
-
socket =
/data/seven/mysql.sock
-
port =
3307
-
log-error =
/data/seven/mysql.log
-
pid-file =
/data/seven/mysqld.pid
2.使用multi,这是一个管理的bash脚本,将他复制过来
cp /usr/local/mysql-5.7/support-files/mysqld_multi.server /etc/init.d/
chmod +x /etc/init.d/mysqld_multi.server
要修改一下脚本,默认目录不符合当前的配置
vim /etc/init.d/mysqld_multi.server
basedir=/usr/local/mysql-5.6bindir=/usr/local/mysql-5.6/bin
复制
3.使用
查看配置的3006和3307是否识别到了
/etc/init.d/mysqld_multi.server report
这里可以看到3306是已经启动的
启动单独的3307端口
/etc/init.d/mysqld_multi.server start 3307
已经启动了
验证
netstat -unltp | grep :3306
netstat -unltp | grep :3307
连接
mysql -S /data/seven/mysql.sock
也可以用ip+端口的方式连接,如果用socket连接,那端口和ip就没意义了。使用的将是本地登陆
mysql -uroot -P3307 -h127.0.0.1
连接修改,这里要和上面不同,5.7版本有点小差别
mysql -uroot -P3307 --socket=/data/seven/mysql.sock
mysql>
use mysql;
mysql>
UPDATE user SET authentication_string=PASSWORD("123456") WHERE user='root';
五.muliti使用
启动全部实例:
/usr/local/mysql/bin/mysqld_multi start
查看全部实例状态:
/usr/local/mysql/bin/mysqld_multi report
启动单个实例:
/usr/local/mysql/bin/mysqld_multi start 3306
停止单个实例:
/usr/local/mysql/bin/mysqld_multi stop 3306
查看单个实例状态:
/usr/local/mysql/bin/mysqld_multi report 3306