您好,登錄后才能下訂單哦!
#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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。