MySQL安装
下载:http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.6/
(1)解压
tar -zxvf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
(2)创建软链接
ln -sv /usr/local/mysql-5.6.46-linux-glibc2.12-x86_64 /usr/local/mysql
(3)创建mysql 用户
useradd -M -s /sbin/nologin mysql
(4)创建目录结构和授权
mkdir /opt/data/{3306,3307}/ -p
chown -R mysql.mysql /opt/data
(5)添加环境变量
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
(6)创建my.cnf文件 nano /etc/my.cnf
[client]
port=3306
socket=/opt/data/mysql.sock
[mysqld_multi]
user=multi_admin
pass=multi_admin
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
log = /opt/data/mysqld_multi.log
[mysqld]
user=mysql
basedir = /usr/local/mysql
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld3306]
mysqld=mysqld
mysqladmin=mysqladmin
datadir=/opt/data/3306/data
port=3306
socket=/opt/data/3306/mysql3306.sock
max_connections=1000
character-set-server=utf8
innodb_file_per_table=1
lower_case_table_names=1
key_buffer_size=512M
innodb_buffer_pool_size = 1024M
sort_buffer_size=1M
read_rnd_buffer_size=1M
read_buffer_size=1M
join_buffer_size=1M
max_heap_table_size=256M
tmp_table_size=256M
max_allowed_packet=64M
skip-name-resolve
skip-external-locking
net_buffer_length=512K
long_query_time=3
slow-query-log=On
slow_query_log_file=/opt/data/3306/log/mysql_slow_query.log
log-error = /opt/data/3306/log/error.log
query_cache_type=on
query_cache_size=64M
query_cache_limit=1M
[mysqld3307]
mysqld=mysqld
mysqladmin=mysqladmin
datadir=/opt/data/3307/data
port=3307
socket=/opt/data/3307/mysql3307.sock
max_connections=1000
character-set-server=utf8
innodb_file_per_table=1
lower_case_table_names=1
key_buffer_size=512M
innodb_buffer_pool_size = 1024M
sort_buffer_size=1M
read_rnd_buffer_size=1M
read_buffer_size=1M
join_buffer_size=1M
max_heap_table_size=256M
tmp_table_size=256M
max_allowed_packet=64M
skip-name-resolve
skip-external-locking
net_buffer_length=512K
long_query_time=3
slow-query-log=On
slow_query_log_file=/opt/data/3307/log/mysql_slow_query.log
log-error = /opt/data/3307/log/error.log
query_cache_type=on
query_cache_size=64M
query_cache_limit=1M
(7)初始化数据库
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/opt/data/3306/data --defaults-file=/etc/my.cnf
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/opt/data/3307/data --defaults-file=/etc/my.cnf
(8)修改单独启动配置
#cd /opt/data/3306/data
#nano my.cnf
[client]
port = 3306
socket = /opt/data/3306/data/mysql3306.sock
[mysqld]
port = 3306
socket = /opt/data/3306/data/mysql3306.sock
datadir = /opt/data/3306/data
max_connections=1000
character-set-server=utf8
innodb_file_per_table=1
lower_case_table_names=1
log_error=/opt/data/3306/data/mysql3306.err
#cd /opt/data/3307/data
#nano my.cnf
[client]
port = 3307
socket = /opt/data/3307/data/mysql3307.sock
[mysqld]
port = 3307
socket = /opt/data/3307/data/mysql3307.sock
datadir = /opt/data/3307/data
max_connections=1000
character-set-server=utf8
innodb_file_per_table=1
lower_case_table_names=1
log_error=/opt/data/3307/data/mysql3307.err
(9)启动多实例
/usr/local/mysql/bin/mysqld_safe --defaults-file=/opt/data/3306/data/my.cnf &
/usr/local/mysql/bin/mysqld_safe --defaults-file=/opt/data/3307/data/my.cnf &
(10)修改密码
/usr/local/mysql/bin/mysqladmin -u root password "123456" -S /opt/data/3306/data/mysql3306.sock
/usr/local/mysql/bin/mysqladmin -u root password "123456" -S /opt/data/3307/data/mysql3307.sock
查看进程
netstat -tulnp
(11)登陆数据库
/usr/local/mysql/bin/mysql -uroot -p -S /opt/data/3306/data/mysql3306.sock
/usr/local/mysql/bin/mysql -uroot -p -S /opt/data/3307/data/mysql3307.sock
GRANT SHUTDOWN ON *.* TO 'multi_admin'@'localhost' IDENTIFIED BY 'multi_admin'; FLUSH PRIVILEGES; # 该账号用于 mysqld_multi 实例管理
GRANT ALL PRIVILEGES ON *.* TO 'dba_user'@'%' IDENTIFIED BY PASSWORD '*3F4D6E9B7A42AD6D870BBDB137B8C00B097A4AB8' WITH GRANT OPTION; FLUSH PRIVILEGES;
ps -ef | grep mysql
杀掉mysql 进程
(12)使用mysqld_multi进行多实例管理
启动全部实例:/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
注:mysqld_multi stop无效问题
GRANT SHUTDOWN ON *.* TO 'multi_admin'@'localhost' IDENTIFIED BY 'multi_admin'; FLUSH PRIVILEGES;
https://www.cnblogs.com/qizhelongdeyang/p/6292966.html
https://blog.51cto.com/jinlong/2059076
https://blog.csdn.net/weixin_34001430/article/details/89869565
https://www.jianshu.com/p/3bf7fe15dd45
https://www.cnblogs.com/lovelinux199075/p/9118708.html