安裝方式分為rpm和源碼編譯安裝兩種,本文是采用mysql源碼編譯方式,編譯器使用Cmake。軟件需要mysql-5.5.29.tar.gz和cmake-2.8.10.2.tar.gz,請自行下載。
[root@localhost]# mkdir -p /usr/local/mysql //安裝mysql
[root@localhost]# mkdir -p /usr/local/mysql/data //存放數(shù)據(jù)庫
[root@localhost] groupadd mysql
[root@localhost] useradd -r -g mysql 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
[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等以上文件的話,恭喜你已經(jīng)成功安裝了mysql。
[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
[root@localhost mysql]# cp support-files/my-medium.cnf /etc/my.cnf cp:是否覆蓋"/etc/my.cnf"? y
[root@localhost mysql]# cd /usr/local/mysql
[root@localhost mysql]# scripts/mysql_install_db --user=mysql
[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 //使剛才的修改生效
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# ./bin/mysqld_safe --user=mysql & //啟動MySQL,但不能停止 mysqladmin -u root -p shutdown //此時root還沒密碼,所以為空值,提示輸入密碼時,直接回車即可。
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql
[root@localhost mysql]# service mysql start Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid). 啟動失敗: 我這里是權(quán)限問題,先改變權(quán)限 [root@localhost mysql]# chown -R mysql:mysql /usr/local/mysql 接著啟動服務(wù)器
[root@localhost mysql]# /etc/init.d/mysql start
[root@localhost mysql]# mysql -u root mysql
mysql> use mysql;
mysql> desc user;
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; //為root添加遠程連接的能力
mysql> update user set Password = password('123456') where User='root'; //設(shè)置root用戶密碼
mysql> select Host,User,Password from user where User='root';
mysql> flush privileges;
mysql> exit
[root@localhost mysql]# mysql -u root -p Enter password:123456 若還不能進行遠程連接,關(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ā)表評論