#mysql安装脚本安装好后
mkdir -v /usr/share/mysql/mysql-files
mkdir -vp /data/mysql_data{1..4}
* 修改 MySQL 二进制包目录的所属用户与所属组
chown root.mysql -R /usr/share/mysql
* 修改 MySQL 多实例数据目录与 数据导入/导出专放目录的所属用户与所属组
chown mysql.mysql -R /usr/share/mysql/mysql-files /data/mysql_data{1..4}
* 配置 MySQL 配置文件
cat>> /etc/multi.cnf<<EOF
[mysqld_multi]
mysqld = /usr/sbin/mysqld
mysqladmin = /usr/bin/mysqladmin
log = /tmp/mysql_multi.log
[mysqld1]
datadir = /data/mysql_data1
socket = /tmp/mysql.sock1
port = 3307
user = mysql
performance_schema = off
innodb_buffer_pool_size = 32M
bind_address = 0.0.0.0
skip-name-resolve = 0
[mysqld2]
datadir = /data/mysql_data2
socket = /tmp/mysql.sock2
port = 3308
user = mysql
performance_schema = off
innodb_buffer_pool_size = 32M
bind_address = 0.0.0.0
skip-name-resolve = 0
[mysqld3]
datadir = /data/mysql_data3
socket = /tmp/mysql.sock3
port = 3309
user = mysql
performance_schema = off
innodb_buffer_pool_size = 32M
bind_address = 0.0.0.0
skip-name-resolve = 0
EOF
* 初始化各个实例 [ 初始化完成后会自带随机密码在输出日志中 ] /var/log/mysqld.log
/usr/sbin/mysqld --initialize --user=mysql --datadir=/data/mysql_data1
/usr/sbin/mysqld --initialize --user=mysql --datadir=/data/mysql_data2
/usr/sbin/mysqld --initialize --user=mysql --datadir=/data/mysql_data3
* 实例开启
mysqld_multi --defaults-extra-file=/etc/multi.cnf start
测试
mysql -uroot -S /tmp/mysql.sock1 -p 密码在初始化的时候会给root随机密码
grep 'temporary password' /var/log/mysqld.log| awk -F: '{print $4}'|awk 'NR==2{print}'
scok2 就将NR==3
rep 'temporary password' /var/log/mysqld.log| awk -F: '{print $4}'|awk 'NR==3{print}'
依次类推
ALTER USER 'root'@'localhost' IDENTIFIED BY 'abc123'; 先改密码
增删点数据对比下另一个实例的内容就可以
create database test3306;
show databases;
默认情况下,mysql只允许本地登录,如果要开启远程连接,则需要修改/etc/mysql/my.conf文件。
一、修改/etc/mysql/my.conf
找到bind-address = 127.0.0.1这一行
改为bind-address = 0.0.0.0即可
为需要远程登录的用户赋予权限
支持root用户允许远程连接mysql数据库
grant all privileges on *.* to 'root'@'%' identified by 'abc123' with grant option;
flush privileges;
use mysql;
select user, host from user;
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。