标签:设置密码 name serve bin mys word comm roo ref
# 什么是 Mysql 单实例?
一个进程 + 多个线程 + 一个预分配的内存空间
# Mysql 多实例
多个进程 + 多个线程 + 多个预分配的内存空间(分配给每个 Mysql 单实例)
# mysql 多实例,即在单台服务器上启动多个实例,也是多个配置文件启动数据库
mysql多个配置文件:
1.多个端口(配置 my.cnf,使用 TCP/IP 连接时指定相应端口)
2.多个 Socket 文件(配置 my.cnf,使用 Socket 连接时指定相应路径)
3.多个日志文件(配置 my.cnf)
4.多个 Server_id(配置 my.cnf)
5.多个数据目录(初始化时指定 datadir)
[root@db03 ~]# mkdir /service/{3307,3308,3309}
[root@db03 ~]# vim /service/3307/my.cnf
[mysqld]
basedir = /service/mysql
datadir = /service/3307/data
port=3307
socket=/service/3307/mysql.sock
server_id=1
log_err=/service/3307/data/mysql.err
log_bin=/service/3307/data/mysql-bin
[root@db03 ~]# vim /service/3308/my.cnf
[mysqld]
basedir = /service/mysql
datadir = /service/3308/data
port=3308
socket=/service/3308/mysql.sock
server_id=2
log_err=/service/3308/data/mysql.err
log_bin=/service/3308/data/mysql-bin
[root@db03 ~]# vim /service/3309/my.cnf
[mysqld]
basedir = /service/mysql
datadir = /service/3309/data
port=3309
socket=/service/3309/mysql.sock
server_id=3
log_err=/service/3309/data/mysql.err
log_bin=/service/3309/data/mysql-bin
[root@db03 scripts]# ./mysql_install_db --defaults-file=/service/3307/my.cnf --user=mysql --basedir=/service/mysql --datadir=/service/3307/data
[root@db03 scripts]# ./mysql_install_db --defaults-file=/service/3308/my.cnf --user=mysql --basedir=/service/mysql --datadir=/service/3308/data
[root@db03 scripts]# ./mysql_install_db --defaults-file=/service/3309/my.cnf --user=mysql --basedir=/service/mysql --datadir=/service/3309/data
[root@db03 service]# chown -R mysql.mysql /service/
[root@db03 service]# mysqld_safe --defaults-file=/service/3309/my.cnf &
[root@db03 service]# mysqld_safe --defaults-file=/service/3308/my.cnf &
[root@db03 service]# mysqld_safe --defaults-file=/service/3307/my.cnf &
[root@db03 service]# mysql -S /service/3307/mysql.sock -e "show variables like ‘server_id‘"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 1 |
+---------------+-------+
[root@db03 service]# mysql -S /service/3308/mysql.sock -e "show variables like ‘server_id‘"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 2 |
+---------------+-------+
[root@db03 service]# mysql -S /service/3309/mysql.sock -e "show variables like ‘server_id‘"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 3 |
+---------------+-------+
[root@db03 service]# mysqladmin -S /service/3307/mysql.sock -uroot password ‘123‘
Warning: Using a password on the command line interface can be insecure.
[root@db03 service]# mysqladmin -S /service/3308/mysql.sock -uroot password ‘123‘
Warning: Using a password on the command line interface can be insecure.
[root@db03 service]# mysqladmin -S /service/3309/mysql.sock -uroot password ‘123‘
Warning: Using a password on the command line interface can be insecure.
[root@db03 service]# mysql -S /service/3307/mysql.sock -uroot -p
Enter password:
# 简单连接方式,也可以不指定密码,使用交互输入密码
[root@db03 service]# cat /usr/bin/mysql3307
mysql -S /service/3307/mysql.sock -uroot -p123
[root@db03 service]# cat /usr/bin/mysql3308
mysql -S /service/3308/mysql.sock -uroot -p123
[root@db03 service]# cat /usr/bin/mysql3309
mysql -S /service/3309/mysql.sock -uroot -p123
[root@db03 service]# chmod +x /usr/bin/mysql33*
标签:设置密码 name serve bin mys word comm roo ref
原文地址:https://www.cnblogs.com/zzzwqh/p/13281078.html