日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

DBA(四):数据读写分离,MySQL多实例操作

發(fā)布時間:2025/3/21 数据库 12 豆豆
生活随笔 收集整理的這篇文章主要介紹了 DBA(四):数据读写分离,MySQL多实例操作 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

數(shù)據(jù)讀寫分離

MySQL讀寫分離

概念:把客戶端查詢數(shù)據(jù)的請求和存儲數(shù)據(jù)的SQL命令,分別給不同的數(shù)據(jù)庫服務器處理

讀寫分離的原理

  • 由MySQL代理面向客戶端提供服務
  • 收到SQL的寫請求時,交給master服務器處理
  • 收到SQL的讀請求時,交給slave服務器處理

讀寫分離拓撲圖

部署maxscale服務

Maxscale代理軟件

  • 由MariaDB公司開發(fā)
  • 下載地址
  • 軟件包在此提取碼:5x5c

構建MySQL讀寫分離

  • 部署MySQL一主一從結構
    • 主服務器 192.168.4.51
    • 從服務器 192.168.4.52
  • 部署MySQL代理服務器
    • 裝包、修改配置文件、啟動服務
  • 測試配置
    • 客戶端連接代理服務訪問數(shù)據(jù)
    1.配置MySQL主從同步:host52數(shù)據(jù)庫服務器作為host51的從服務器host51主機:[root@host51 ~]# vim /etc/my.cnf [mysqld] server_id=51 #指定服務器id號 log_bin=master51 #啟用binlog日志,并指定文件名前綴 [root@host53 mysql]# systemctl restart mysqld [root@host51 ~]# mysql -uroot -p123456 mysql> grant replication slave on *.* to repluser@"%" identified by "123qqq...A"; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> show master status; +-----------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +-----------------+----------+--------------+------------------+-------------------+ | master51.000003 | 365 | | | | +-----------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)host52主機:[root@host52 ~]# vim /etc/my.cnf[mysqld]server_id=52 [root@host54 ~]# systemctl restart mysqld [root@host52 ~]# mysql -uroot -p123456mysql> change master to-> master_host="192.168.4.51",-> master_user="repluser",-> master_password="123qqq...A",-> master_log_file="master51.000003",-> master_log_pos=365; Query OK, 0 rows affected, 2 warnings (0.08 sec)mysql> start slave; Query OK, 0 rows affected (0.01 sec)mysql> show slave status \G *************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 192.168.4.51Master_User: repluserMaster_Port: 3306Connect_Retry: 60Master_Log_File: master51.000003Read_Master_Log_Pos: 154Relay_Log_File: host52-relay-bin.000011Relay_Log_Pos: 365Relay_Master_Log_File: master51.000003Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 154Relay_Log_Space: 6474Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 51Master_UUID: 6d7b632c-4e3f-11ea-8a8d-000c29875030Master_Info_File: /var/lib/mysql/master.infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec)此時做初步測試:首先在host51主機上查看授權用戶的權限 mysql> show grants for repluser@"%"; +--------------------------------------------------+ | Grants for repluser@% | +--------------------------------------------------+ | GRANT REPLICATION SLAVE ON *.* TO 'repluser'@'%' | +--------------------------------------------------+ 1 row in set (0.00 sec)mysql> create database aaa; Query OK, 1 row affected (0.06 sec)mysql> create table aaa.b(name char(10)); Query OK, 0 rows affected (0.24 sec)mysql> insert into aaa.b values("zzz"); Query OK, 1 row affected (0.11 sec)mysql> select * from aaa.b; +------+ | name | +------+ | zzz | +------+ 1 row in set (0.00 sec)在host52主機上連接數(shù)據(jù)庫服務器,查看是否有剛剛寫入的數(shù)據(jù) mysql> select * from aaa.b; +------+ | name | +------+ | zzz | +------+ 1 row in set (0.00 sec)***** 環(huán)境要求:關閉防火墻,保證yum源可以正常使用,安裝提供服務的軟件 配置讀寫分離服務器192.168.4.57,具體操作如下:1.安裝軟件maxscale-2.1.2-1.rhel.7.x86_64.rpm [root@host57 ~]# rpm -ivh maxscale-2.1.2-1.rhel.7.x86_64.rpm #安裝maxscale 提供服務程序和管理命令 [root@host57 ~]# max [Tab][Tab] #查看maxscale的命令 maxadmin maxbinlogcheck maxpasswd maxavrocheck maxkeys maxscale 2.修改配置文件 [root@host57 ~]# ls /etc/maxscale.cnf /etc/maxscale.cnf[root@host57 ~]# cp /etc/maxscale.cnf /root[root@host57 ~]# vim /etc/maxscale.cnf9 [maxscale] #定義線程個數(shù)10 threads=auto #改為自動模式...18 [server1] #定義數(shù)據(jù)庫服務器19 type=server20 address=192.168.4.51 #master主機IP地址21 port=330622 protocol=MySQLBackend23 24 [server2] #定義數(shù)據(jù)庫服務器225 type=server26 address=192.168.4.52 #slave主機IP地址27 port=330628 protocol=MySQLBackend35 [MySQL Monitor] #定義數(shù)據(jù)庫監(jiān)視的數(shù)據(jù)庫節(jié)點36 type=monitor37 module=mysqlmon38 servers=server1,server2 #監(jiān)控的數(shù)據(jù)庫列表,不能寫IP39 user=maxscalemon #監(jiān)控用戶40 passwd=123qqq...A #密碼41 monitor_interval=1000052 #[Read-Only Service] #第52行到58行注釋掉,取消定義只讀服務53 #type=service54 #router=readconnroute55 #servers=server156 #user=myuser57 #passwd=mypwd58 #router_options=slave63 [Read-Write Service] #定義讀寫分離數(shù)據(jù)庫的節(jié)點64 type=service65 router=readwritesplit66 servers=server1,server2 #主,從服務器主機名67 user=maxscalerouter #監(jiān)控路由用戶68 passwd=123qqq...A #密碼69 max_slave_connections=100%75 [MaxAdmin Service] #定義管理服務76 type=service77 router=cli85 #[Read-Only Listener] #取消定義只讀服務的端口,注釋掉86 #type=listener87 #service=Read-Only Service88 #protocol=MySQLClient89 #port=400891 [Read-Write Listener] #定義讀寫分離服務的端口號節(jié)點92 type=listener93 service=Read-Write Service94 protocol=MySQLClient95 port=400697 [MaxAdmin Listener] #定義管理服務的端口號節(jié)點98 type=listener99 service=MaxAdmin Service 100 protocol=maxscaled 101 socket=default 102 port=4016 #自己定義管理服務的端口號,范圍0-65535,但建議不要設置在1024以內(nèi),1024以內(nèi)的端口都已經(jīng)有固定的服務 [root@host57 ~]# sed -i '/#/d' /etc/maxscale.cnf #可以將配置文件里的注釋刪除3.添加授權用戶根據(jù)maxscale.cnf文件配置,在主、從服務器上添加對應的授權用戶,因為兩臺數(shù)據(jù)庫服務器是主從同步結構,只在主數(shù)據(jù)庫服務器添加用戶即可,從服務器會自動同步mysql> grant replication slave ,replication client on *.* to maxscalemon@"%" identified by "123qqq...A"; #授權監(jiān)控用戶 Query OK, 0 rows affected, 1 warning (0.07 sec)mysql> grant select on mysql.* to maxscalerouter@"%" identified by "123qqq...A"; #授權路由用戶 Query OK, 0 rows affected, 1 warning (0.00 sec)4.查看授權用戶 mysql> select host , user from mysql.user where user in ("maxscalerouter","maxscalemon"); +------+----------------+ | host | user | +------+----------------+ | % | maxscalemon | | % | maxscalerouter | +------+----------------+ 2 rows in set (0.08 sec)在代理服務器57主機上,測試授權用戶 [root@host57 ~]#yum -y install mariadb //安裝提供mysql命令的軟件包 [root@host57 ~]# mysql -h 192.168.4.51 -umaxscalemon -p123qqq…A [root@host57 ~]# mysql -h 192.168.4.52 -umaxscalemon -p123qqq…A [root@host57 ~]# mysql -h 192.168.4.51 -umaxscalerouter -p123qqq…A [root@host57 ~]#mysql -h 192.168.4.52 -umaxscalerouter -p123qqq…A5.啟動maxscale代理服務 [root@host57 ~]# maxscale -f /etc/maxscale.cnf [root@host57 ~]# netstat -nutlp | grep maxscale #查看maxscale端口,4006為讀寫分離端口,4016為管理服務端口 tcp6 0 0 :::4006 :::* LISTEN 11249/maxscale tcp6 0 0 :::4016 :::* LISTEN 11249/maxscale [root@host57 ~]# ps -C maxscale #查看進程PID TTY TIME CMD11249 ? 00:00:00 maxscale測試配置1.查看監(jiān)控信息(在主機57本機訪問自己) [root@host57 ~]# maxadmin -uadmin -pmariadb -P4016 MaxScale> list servers #只能有一個空格!! Servers. -------------------+-----------------+-------+-------------+-------------------- Server | Address | Port | Connections | Status -------------------+-----------------+-------+-------------+-------------------- server1 | 192.168.4.51 | 3306 | 0 | Master, Running server2 | 192.168.4.52 | 3306 | 0 | Slave, Running -------------------+-----------------+-------+-------------+--------------------2.在主服務器上添加授權連接用戶 在主服務器上添加即可,從服務器會自動同步 [root@host50 ~]# which mysql /usr/bin/mysql [root@host50 ~]# rpm -q mariadb mariadb-5.5.56-2.el7.x86_64[root@host50 ~]# mysql -h192.168.4.58 -P4006 -ujim -p123qqq...A ERROR 1045 (28000): Access denied for user 'jim'@'::ffff:192.168.4.50' (using password: YES) #客戶端訪問服務器只能使用路由用戶訪問在主服務器添加授權用戶給客戶端連接使用 客戶端使用授權用戶連接 mysql> create database db6; Query OK, 1 row affected (0.00 sec)mysql> create table db6.user(name char(15)); Query OK, 0 rows affected (0.06 sec)mysql> grant select ,insert on db6.* to jim@"%" identified by "123qqq...A"; Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> desc db6.user; +-------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+-------+ | name | char(15) | YES | | NULL | | +-------+----------+------+-----+---------+-------+ 1 row in set (0.00 sec)mysql> select user ,host from mysql.user; +----------------+--------------+ | user | host | +----------------+--------------+ | haha | % | | jim | % | | maxscalemon | % | | maxscalerouter | % | | repluser | % | | webadmin | % | | admin | 192.168.4.% | | root | 192.168.4.52 | | admin2 | localhost | | mysql.sys | localhost | | root | localhost | | tian | localhost | +----------------+--------------+ 12 rows in set (0.00 sec)在host52主機上面查看mysql> desc db6.user; +-------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+-------+ | name | char(15) | YES | | NULL | | +-------+----------+------+-----+---------+-------+ 1 row in set (0.00 sec)在host50客戶端訪問代理服務器,插入數(shù)據(jù)可以成功查看 [root@host50 ~]# mysql -h192.168.4.58 -P4006 -ujim -p123qqq...A MySQL [(none)]> insert into db6.user values("bob"); Query OK, 1 row affected (0.01 sec)MySQL [(none)]> select * from db6.user; +------+ | name | +------+ | bob | +------+ 1 row in set (0.01 sec)在host51以及host52主機也可以看到插入的數(shù)據(jù) mysql> select * from db6.user; +------+ | name | +------+ | bob | +------+ 1 row in set (0.00 sec)

    MySQL多實例

    多實例概述

    • 什么是多實例?
    • 在一臺物理主機上運行多個數(shù)據(jù)庫服務
    • 為什么要使用多實例?
    • 節(jié)約運維成本
    • 提高硬件利用率

    配置多實例

    環(huán)境準備:
    在192.168.4.57主機上配置,要提前安裝軟件包mysql-5.7.20可以支持配置多實例
    軟件包在此!提取碼:iptb

    [root@host57 ~]# ls mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz [root@host57 ~]# tar -zxvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz[root@host57 ~]# ls mysql-5.7.20-linux-glibc2.12-x86_64 bin COPYING docs include lib man README share support-files[root@host57 ~]# mv mysql-5.7.20-linux-glibc2.12-x86_64 /usr/local/mysql[root@host57 ~]# cd /usr/local/mysql[root@host57 mysql]# ls bin(SQL命令) COPYING docs(幫助文檔,二進制) include(源碼調(diào)用程序文件) lib(源碼調(diào)用模塊) man(幫助文檔) README share(幫助文檔) support-files(配置文件模板)[root@host57 mysql]# PATH=/usr/local/mysql/bin:$PATH #將path變量賦新值[root@host57 mysql]# echo $PATH /usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin[root@host57 mysql]# mysql[Tab][Tab] mysql mysqld_multi mysql_secure_installation mysqladmin mysqld_safe mysqlshow mysqlbinlog mysqldump mysqlslap mysqlcheck mysqldumpslow mysql_ssl_rsa_setup mysql_client_test_embedded mysql_embedded mysqltest_embedded mysql_config mysqlimport mysql_tzinfo_to_sql mysql_config_editor mysql_install_db mysql_upgrade mysqld mysql_plugin mysqlxtest mysqld-debug mysqlpump [root@host57 mysql]# vim /etc/bashrc #在文檔結尾添加永久配置全局變量 export PATH=/usr/local/mysql/bin:$PATH[root@host57 ~]# yum -y install libaio #安裝依賴包[root@host57 ~]# useradd mysql #添加進程所有者用戶,一定不要忘記創(chuàng)建!!!!創(chuàng)建并編寫主配置文件 /etc/my.cnf多實例服務的運行配置 如果原本有下載mariadb或者安裝過mysql軟件就會產(chǎn)生/etc/my.cnf,要先刪除 [root@host57 ~]# rm -rf /etc/my.cnfsocket文件:當自己訪問自己時,通過socket文件傳遞數(shù)據(jù),是訪問mysql接口程序的文件,套接字文件,虛擬文件,服務啟動時有該文件,服務關閉時文件即消失[root@host57 ~]# vim /etc/my.cnf [mysqld_multi] #啟用多實例 mysqld=/usr/local/mysql/bin/mysqld_safe #指定進程文件路徑 mysqladmin=/usr/local/mysql/bin/mysqladminer=root #指定管理命令路徑 user=root #指定進程用戶[mysqld1] #實例進程名稱 datadir=/dir1 #數(shù)據(jù)庫目錄,要手動創(chuàng)建 log-error=/dir1/mysqld1.error #錯誤日志位置 socket=/dir1/mysqld1.sock #指定sock文件的路徑和名稱 pid-file=/dir1/mysqld1.pid #進程pid號文件位置 port=3307 #端口號(自定義,不能是已經(jīng)存在的默認的端口)[mysqld2] datadir=/dir2 log-error=/dir2/mysqld2.error socket=/dir2/mysqld2.sock pid-file=/dir2/mysqld2.pid port=3308[root@host57 ~]# mkdir /dir1 #創(chuàng)建數(shù)據(jù)庫目錄 [root@host57 ~]# mkdir /dir2 啟動服務(首次啟動服務會創(chuàng)建root登錄的初始密碼) [root@host57 ~]# ls /dir1[root@host57 ~]# mysqld_multi start 1 #開啟第一個服務 [root@host57 ~]# ss -nutlp | grep 3307 tcp LISTEN 0 80 :::3307 :::* users:(("mysqld",pid=11365,fd=20))[root@host57 ~]# ps -C mysqldPID TTY TIME CMD11365 pts/0 00:00:00 mysqld[root@host57 ~]# ls /dir1 #查看數(shù)據(jù)庫目錄文件列表 auto.cnf ib_logfile0 mysql mysqld1.sock sys ib_buffer_pool ib_logfile1 mysqld1.error mysqld1.sock.lock ibdata1 ibtmp1 mysqld1.pid performance_schema[root@host57 ~]# mysql -uroot -p',hi=N2b,8/qI' -S /dir1/mysqld1.sock mysql> alter user root@"localhost" identified by "123456"; #修改新密碼[root@host57 ~]# mysql -uroot -p123456 -S /dir1/mysqld1.sock mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)[root@host57 ~]# ls /dir2[root@host57 ~]# mysqld_multi start 2 #啟動實例2[root@host57 ~]# ls /dir2 #查看數(shù)據(jù)庫目錄文件列表 auto.cnf ib_logfile0 mysql mysqld2.sock.lock ib_buffer_pool ib_logfile1 mysqld2.error performance_schema ibdata1 ibtmp1 mysqld2.sock sys[root@host57 ~]# ss -nutlp | grep 3308 tcp LISTEN 0 80 :::3308 :::* users:(("mysqld",pid=11734,fd=20))[root@host57 ~]# ps -C mysqldPID TTY TIME CMD11365 pts/0 00:00:01 mysqld11734 pts/0 00:00:00 mysqld[root@host57 ~]# mysql -uroot -p"dsvL3O<Nzo4%" -S /dir2/mysqld2.sock mysql> alter user root@"localhost" identified by "123456"; #修改密碼 Query OK, 0 rows affected (0.03 sec)[root@host57 ~]# mysql -uroot -p123456 -S /dir2/mysqld2.sock #新密碼登錄 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)############## 如果啟動服務而且有端口號但無法進入數(shù)據(jù)庫,可以進行如下操作: rm -rf /dir1/* killall -9 mysqld #如果沒有killall命令,請yum -y install psmisc 檢查配置文件/etc/my.cnf 再次重新啟動服務mysqld_multi start 1 ################停止服務(如果停止不了服務就殺掉進程) [root@host57 ~]# ss -nutlp | grep mysqld tcp LISTEN 0 80 :::3307 :::* users:((mysqld",pid=11365,fd=20)) tcp LISTEN 0 80 :::3308 :::* users:((mysqld",pid=11734,fd=20))[root@host57 ~]# mysqld_multi --user=root --password=123456 stop 1 #關閉實例1的服務[root@host57 ~]# ss -nutlp | grep mysqld tcp LISTEN 0 80 :::3308 :::* users:((mysqld",pid=11734,fd=20))[root@host57 ~]# mysqld_multi start 1 #再次啟動[root@host57 ~]# mysql -uroot -p123456 -S /dir1/mysqld1.sock #此時再次啟動時直接用修改后的密碼登錄即可 [root@host57 ~]# ss -nutlp | grep mysqld tcp LISTEN 0 80 :::3307 :::* users:((mysqld",pid=11945,fd=28)) tcp LISTEN 0 80 :::3308 :::* users:((mysqld",pid=11734,fd=20))添加實例3.自定義運行參數(shù)[root@host57 ~]# vim /etc/my.cnf [mysqld_multi] mysqld=/usr/local/mysql/bin/mysqld_safe mysqladmin=/usr/local/mysql/bin/mysqladmin user=root[mysqld1] datadir=/dir1 log-error=/dir1/mysqld1.error socket=/dir1/mysqld1.sock pid-file=/dir1/mysqld1.pid port=3307[mysqld2] datadir=/dir2 log-error=/dir2/mysqld2.error socket=/dir2/mysqld2.sock pid-file=/dir2/mysqld2.pid port=3308[mysqld3] datadir=/dir3 log-error=/dir3/mysqld3.error socket=/dir3/mysqld3.sock pid-file=/dir3/mysqld3.pid port=3309[root@host57 ~]#mkdir /dir3 [root@host57 ~]# ls /dir3 [root@host57 ~]# mysqld_multi start 3 [root@host57 ~]# ls /dir3 auto.cnf ib_logfile0 mysql mysqld3.sock sys ib_buffer_pool ib_logfile1 mysqld3.error mysqld3.sock.lock ibdata1 ibtmp1 mysqld3.pid performance_schema [root@host57 ~]# ss -nutlp | grep mysqld tcp LISTEN 0 80 :::3307 :::* users:((mysqld",pid=11945,fd=28)) tcp LISTEN 0 80 :::3308 :::* users:((mysqld",pid=11734,fd=20)) tcp LISTEN 0 80 :::3309 :::* users:((mysqld",pid=12140,fd=20))[root@host57 ~]# mysql -uroot -p'Iorf=e<ef6aM' -S /dir3/mysqld3.sock mysql> alter user root@"localhost" identified by "123456"; [root@host57 ~]# mysql -uroot -p123456 -S /dir3/mysqld3.sock允許客戶端50可以連接57主機的實例1服務 ,對db1庫有完全權限,且實例1可以記錄用戶執(zhí)行的SQL命令 [root@host57 ~]# vim /etc/my.cnf[mysqld1] server_id=1 log_bin=mysqld1 datadir=/dir1 log-error=/dir1/mysqld1.error socket=/dir1/mysqld1.sock pid-file=/dir1/mysqld1.pid port=3307[root@host57 ~]# mysqld_multi --user=root --password=123456 stop 1 [root@host57 ~]# mysqld_multi start 1 [root@host57 ~]# mysql -uroot -p123456 -S /dir1/mysqld1.sock mysql> show master status; +----------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +----------------+----------+--------------+------------------+-------------------+ | mysqld1.000001 | 154 | | | | +----------------+----------+--------------+------------------+-------------------+ 1 row in set (0.04 sec)mysql> grant all on db1.* to yaya@"192.168.4.50" identified by "123456"; Query OK, 0 rows affected, 1 warning (0.07 sec)mysql> select user ,host from mysql.user; +---------------+--------------+ | user | host | +---------------+--------------+ | yaya | 192.168.4.50 | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +---------------+--------------+ 4 rows in set (0.00 sec)mysql> show grants for yaya@"192.168.4.50" ; +----------------------------------------------------------+ | Grants for yaya@192.168.4.50 | +----------------------------------------------------------+ | GRANT USAGE ON *.* TO 'yaya'@'192.168.4.50' | | GRANT ALL PRIVILEGES ON `db1`.* TO 'yaya'@'192.168.4.50' | +----------------------------------------------------------+ 2 rows in set (0.00 sec)[root@host50 ~]# mysql -h192.168.4.57 -uyaya -p123456 -P3307 MySQL [(none)]> show grants; +----------------------------------------------------------+ | Grants for yaya@192.168.4.50 | +----------------------------------------------------------+ | GRANT USAGE ON *.* TO 'yaya'@'192.168.4.50' | | GRANT ALL PRIVILEGES ON `db1`.* TO 'yaya'@'192.168.4.50' | +----------------------------------------------------------+ 2 rows in set (0.00 sec)MySQL [(none)]> create database db1; Query OK, 1 row affected (0.02 sec)MySQL [(none)]> create table db1.user(name char(10)); Query OK, 0 rows affected (0.02 sec)MySQL [(none)]> insert into db1.user values("aaa"); Query OK, 1 row affected (0.04 sec)MySQL [(none)]> select * from db1.user; +------+ | name | +------+ | aaa | +------+ 1 row in set (0.00 sec)在host57主機查看 [root@host57 ~]# mysql -uroot -p123456 -S /dir1/mysqld1.sock mysql> select * from db1.user; +------+ | name | +------+ | aaa | +------+ 1 row in set (0.00 sec)

    總結

    以上是生活随笔為你收集整理的DBA(四):数据读写分离,MySQL多实例操作的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。