龍巖易富通網(wǎng)絡(luò)科技有限公司

龍巖小程序開(kāi)發(fā),龍巖分銷(xiāo)系統(tǒng)

CentOS-6.3安裝Mysql-5.5.29

2015.09.10 | 1360閱讀 | 0條評(píng)論 | 數(shù)據(jù)庫(kù)

安裝方式分為rpm和源碼編譯安裝兩種,本文是采用mysql源碼編譯方式,編譯器使用Cmake。軟件需要mysql-5.5.29.tar.gz和cmake-2.8.10.2.tar.gz,請(qǐng)自行下載。

5.創(chuàng)建mysql的安裝目錄及數(shù)據(jù)庫(kù)存放目錄

[root@localhost]# mkdir -p /usr/local/mysql //安裝mysql 

[root@localhost]# mkdir -p /usr/local/mysql/data //存放數(shù)據(jù)庫(kù)

6.創(chuàng)建mysql用戶(hù)及用戶(hù)組

[root@localhost] groupadd mysql 

[root@localhost] useradd -r -g mysql mysql

7.編譯安裝mysql

[root@localhost local]# tar -zxv -f mysql-5.5.29.tar.gz //解壓 

[root@localhost local]# cd mysql-5.5.29 

[root@localhost mysql-5.5.29]#

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306

[root@localhost mysql-5.5.29]# make 

[root@localhost mysql-5.5.29]# make install

8.檢驗(yàn)是否安裝成功

[root@localhost mysql-5.5.29]# cd /usr/local/mysql/ 

[root@localhost mysql]# ls bin 

COPYING data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files 有bin等以上文件的話(huà),恭喜你已經(jīng)成功安裝了mysql。

配置mysql

9.設(shè)置mysql目錄權(quán)限

[root@localhost mysql]# cd /usr/local/mysql //把當(dāng)前目錄中所有文件的所有者設(shè)為root,所屬組為mysql 

[root@localhost mysql]# chown -R root:mysql . 

[root@localhost mysql]# chown -R mysql:mysql data

10.將mysql的啟動(dòng)服務(wù)添加到系統(tǒng)服務(wù)中

[root@localhost mysql]# cp support-files/my-medium.cnf /etc/my.cnf cp:是否覆蓋"/etc/my.cnf"? y

11.創(chuàng)建系統(tǒng)數(shù)據(jù)庫(kù)的表

[root@localhost mysql]# cd /usr/local/mysql

[root@localhost mysql]# scripts/mysql_install_db --user=mysql

12.設(shè)置環(huán)境變量

[root@localhost ~]# vi /root/.bash_profile 在修改PATH=$PATH:$HOME/bin為: PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib 

[root@localhost ~]# source /root/.bash_profile //使剛才的修改生效

13.手動(dòng)啟動(dòng)mysql

[root@localhost ~]# cd /usr/local/mysql 

[root@localhost mysql]# ./bin/mysqld_safe --user=mysql & //啟動(dòng)MySQL,但不能停止 mysqladmin -u root -p shutdown //此時(shí)root還沒(méi)密碼,所以為空值,提示輸入密碼時(shí),直接回車(chē)即可。

14.將mysql的啟動(dòng)服務(wù)添加到系統(tǒng)服務(wù)中

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql

15.啟動(dòng)mysql

[root@localhost mysql]# service mysql start Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid). 啟動(dòng)失?。? 我這里是權(quán)限問(wèn)題,先改變權(quán)限 [root@localhost mysql]# chown -R mysql:mysql /usr/local/mysql 接著啟動(dòng)服務(wù)器 

[root@localhost mysql]# /etc/init.d/mysql start

16.修改MySQL的root用戶(hù)的密碼以及打開(kāi)遠(yuǎn)程連接

[root@localhost mysql]# mysql -u root mysql 

mysql> use mysql; 

mysql> desc user; 

mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; //為root添加遠(yuǎn)程連接的能力 

mysql> update user set Password = password('123456') where User='root'; //設(shè)置root用戶(hù)密碼 

mysql> select Host,User,Password from user where User='root'; 

mysql> flush privileges; 

mysql> exit

17.重新登錄

[root@localhost mysql]# mysql -u root -p Enter password:123456 若還不能進(jìn)行遠(yuǎn)程連接,關(guān)閉防火墻 

[root@localhost]# /etc/rc.d/init.d/iptables stop

FATAL ERROR: Could not find ./bin/my_print_defaults 解決方法:scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

贊 (

發(fā)表評(píng)論