1.MySQL多實例介紹 1.1.什麼是MySQL多實例 MySQL多實例就是在一臺機器上開啟多個不同的服務埠(如:3306,3307),運行多個MySQL服務進程,通過不同的socket監聽不同的服務埠來提供各自的服務:; 1.2.MySQL多實例的特點有以下幾點 1:有效利用伺服器資源,當單 ...
1.MySQL多實例介紹 1.1.什麼是MySQL多實例 MySQL多實例就是在一臺機器上開啟多個不同的服務埠(如:3306,3307),運行多個MySQL服務進程,通過不同的socket監聽不同的服務埠來提供各自的服務:; 1.2.MySQL多實例的特點有以下幾點 1:有效利用伺服器資源,當單個伺服器資源有剩餘時,可以充分利用剩餘的資源提供更多的服務。 2:節約伺服器資源 3:資源互相搶占問題,當某個服務實例服務併發很高時或者開啟慢查詢時,會消耗更多的記憶體、CPU、磁碟IO資源,導致伺服器上的其他實例提供服務的質量下降; 1.3.部署mysql多實例的兩種方式 第一種是使用多個配置文件啟動不同的進程來實現多實例,這種方式的優勢邏輯簡單,配置簡單,缺點是管理起來不太方便; 第二種是通過官方自帶的mysqld_multi使用單獨的配置文件來實現多實例,這種方式定製每個實例的配置不太方面,優點是管理起來很方便,集中管理; 1.4.同一開發環境下安裝兩個資料庫,必須處理以下問題
- 配置文件安裝路徑不能相同
- 資料庫目錄不能相同
- 啟動腳本不能同名
- 埠不能相同
- socket文件的生成路徑不能相同
2.12.4. 查看資料庫是否初始化成功(2) 查看3306資料庫 [root@mysql ~]# cd /data/mysql/mysql_3306/data [root@mysql data]# ls auto.cnf ibdata1 ib_logfile0 ib_logfile1 mysql mysql.pid performance_schema test 查看3307資料庫 [root@mysql ~]# cd /data/mysql/mysql_3307/data [root@mysql data]# ls auto.cnf ibdata1 ib_logfile0 ib_logfile1 mysql mysql.pid performance_schema test 2.13.設置啟動文件 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql 2.14.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 2.14.1.啟動全部實例 [root@mysql ~]# /usr/local/mysql/bin/mysqld_multi start [root@mysql ~]# /usr/local/mysql/bin/mysqld_multi report Reporting MySQL servers MySQL server from group: mysqld3306 is running MySQL server from group: mysqld3307 is running 2.15.查看啟動進程 2.16.修改密碼 mysql的root用戶初始密碼是空,所以需要登錄mysql進行修改密碼,下麵以3306為例: mysql -S /tmp/mysql_3306.sock set password for root@'localhost'=password('123456'); flush privileges; 下次登錄: [root@mysql ~]# mysql -S /tmp/mysql_3306.sock -p Enter password: 2.17.新建用戶及授權 一般新建資料庫都需要新增一個用戶,用於程式連接,這類用戶只需要insert、update、delete、select許可權。 新增一個用戶,並授權如下: grant select,delete,update,insert on *.* to admin@'192.168.0.%' identified by '123456'; flush privileges 2.18.外部軟體登錄資料庫 2.19.測試成功 3.源碼安裝常見報錯信息 1:安裝mysql報錯 checking for tgetent in -lncurses... no checking for tgetent in -lcurses... no checking for tgetent in -ltermcap... no checking for tgetent in -ltinfo... no checking for termcap functions library... configure: error: No curses/termcap library found 原因: 缺少ncurses安裝包 解決方法: yum list|grep ncurses yum -y install ncurses-devel yum install ncurses-devel 2:.../depcomp: line 571: exec: g++: not found make[1]: *** [my_new.o] 錯誤 127 make[1]: Leaving directory `/home/justme/software/mysql-5.1.30/mysys' make: *** [all-recursive] 錯誤 1 解決方法: yum install gcc-c++ 3:.../include/my_global.h:909: error: redeclaration of C++ built-in type `bool' make[2]: *** [my_new.o] Error 1 make[2]: Leaving directory `/home/tools/mysql-5.0.22/mysys' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/home/tools/mysql-5.0.22' make: *** [all] Error 2 是因為gcc-c++是在configure之後安裝的,此時只需重新configure後再編譯make即可。 4:初始化資料庫報錯 報錯現象: root@mysql mysql-6.0.11-alpha]# scripts/mysql_install_db --basedir=/usr/local/mysql/ --user=mysql Installing MySQL system tables... ERROR: 1136 Column count doesn't match value count at row 1 150414 7:15:56 [ERROR] Aborting 150414 7:15:56 [Warning] Forcing shutdown of 1 plugins 150414 7:15:56 [Note] /usr/local/mysql//libexec/mysqld: Shutdown complete Installation of system tables failed! Examine the logs in /var/lib/mysql for more information. You can try to start the mysqld daemon with: shell> /usr/local/mysql//libexec/mysqld --skip-grant & and use the command line tool /usr/local/mysql//bin/mysql to connect to the mysql database and look at the grant tables: shell> /usr/local/mysql//bin/mysql -u root mysql mysql> show tables Try 'mysqld --help' if you have problems with paths. Using --log gives you a log in /var/lib/mysql that may be helpful. The latest information about MySQL is available on the web at http://www.mysql.com/. Please consult the MySQL manual section 'Problems running mysql_install_db', and the manual section that describes problems on your OS. Another information source are the MySQL email archives available at http://lists.mysql.com/. Please check all of the above before mailing us! And remember, if you do mail us, you MUST use the /usr/local/mysql//scripts/mysqlbug script! 原因: 原有安裝的mysql信息沒有刪除乾凈 解決方法: 刪除/var/lib/mysql目錄