Mysql多實例安裝

參考文檔:https://www.cnblogs.com/xuchenliang/p/6843990.htmlhtml

1.部署環境:Centos6.9,Mysql5.6mysql

2.解壓遷移linux

mkdir /usr/local/mysqlc++

tar -xvf mysql-5.6.21-linux-glibc2.5-x86_64.tar.gzweb

mv mysql-5.6.21-linux-glibc2.5-x86_64/* /usr/local/mysqlsql

3.環境設置shell

關閉iptables
臨時關閉:service iptables stop 
永久關閉:chkconfig iptables off
關閉selinux
vi /etc/sysconfig/selinux  
將SELINUX修改成DISABLED,即SELINUX=DISABLED 
建立mysql用戶
groupadd mysql
useradd -g mysql mysql
檢查:id mysql
建立相關目錄
mkdir -p /data/ {3306,3307}
mkdir /data/mysql/mysql_3306/ {data,log,tmp}
mkdir /data/mysql/mysql_3307/ {data,log,tmp}

檢查:tree /data/數據庫

更改目錄權限
chown -R mysql:mysql /data/mysql/ 
chown -R mysql:mysql /usr/local/mysql/
檢查:
ll /data/mysql
ll /usr/local/mysql/
 添加環境變量
echo 'export PATH=$PATH:/usr/local/mysql/bin' >>  /etc/profile 
source /etc/profile  
檢查:cat /etc/profile

 

4. 複製my.cnf文件到etc目錄 and 修改my.cnfvim

cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnfsocket

vim /etc/my.cnf

文本以下:

[client]  
port=3306  
socket=/tmp/mysql.sock  
 
[mysqld_multi]  
mysqld = /usr/local/mysql /bin/mysqld_safe  
mysqladmin = /usr/local/mysql /bin/mysqladmin  
log = /data/mysql/mysqld_multi.log  
 
[mysqld]  
user=mysql  
basedir = /usr/local/mysql  
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES  
 
[mysqld3306]  
mysqld=mysqld  
mysqladmin=mysqladmin  
datadir=/data/mysql/mysql_3306/data  
port=3306  
server_id=3306  
socket=/tmp/mysql_3306.sock  
log-output=file  
slow_query_log = 1  
long_query_time = 1  
slow_query_log_file = /data/mysql/mysql_3306/log/slow.log  
log-error = /data/mysql/mysql_3306/log/error.log  
binlog_format = mixed  
log-bin = /data/mysql/mysql_3306/log/mysql3306_bin  
   
[mysqld3307]  
mysqld=mysqld  
mysqladmin=mysqladmin  
datadir=/data/mysql/mysql_3307/data  
port=3307  
server_id=3307  
socket=/tmp/mysql_3307.sock  
log-output=file  
slow_query_log = 1  
long_query_time = 1  
slow_query_log_file = /data/mysql/mysql_3307/log/slow.log  
log-error = /data/mysql/mysql_3307/log/error.log  
binlog_format = mixed  
log-bin = /data/mysql/mysql_3307/log/mysql3307_bin

 

5.分別初始化3306,3307數據庫

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

1./usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data/mysql/mysql_3306/data --defaults-file=/etc/my.cnf  

2./usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data/mysql/mysql_3307/data --defaults-file=/etc/my.cnf 

 

檢查數據庫是否初始化成功

方法一:

方法二: ll /data/mysql/mysql_3307/data

6.設置啓動文件
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
6.1.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 
6.2.啓動所有實例
[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

檢查:netstat -tlnap|grep mysql

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:

 

7.測試鏈接:新建用戶及受權
通常新建數據庫都須要新增一個用戶,用於程序鏈接,這類用戶只須要insert、update、delete、select權限。
新增一個用戶,並受權以下: 
grant select,delete,update,insert on *.* to admin@'192.168.**.**' identified by '123456'; 
flush privileges

使用Navicat for mysql登錄

 

源碼安裝常見報錯信息
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目錄
相關文章
相關標籤/搜索