1. 程式人生 > >CentOS安裝MySQL 5.6 教程

CentOS安裝MySQL 5.6 教程

1. CentOS安裝MySQL教程

1.1. 安裝條件

活人一個

Linux(centOS)

耳機

1.2. 解除安裝

# yum list installed | grep mysql
# yum -y remove mysql-libs.x86_64

當然還有其它方法

# rpm -qa | grep mysql

如果你係統已安裝,可以選擇進行解除安裝:

# rpm -e mysql  // 普通刪除模式
# rpm -e --nodeps mysql  // 強力刪除模式,如果使用上面命令刪除時,提示有依賴的其它檔案,則用該命令可以對其進行強力刪除

1.3. 安裝

安裝及配置

# wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
# rpm -ivh mysql-community-release-el6-5.noarch.rpm
# yum repolist all | grep mysql

安裝MYSQL資料庫

# yum install mysql-community-server -y

1.4. 設定遠端root

啟動MySQL

# service mysqld start

設定root密碼 有坑注意

# mysql_secure_installation

登陸root賬號

# mysql -uroot -p

建立遠端root使用者

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密碼' WITH GRANT OPTION;
mysql> flush privileges;

1.5. 設定編碼

檢視編碼

mysql> show variables like 'character%';

開啟配置檔案

# vi /etc/my.cnf

新增如下資訊

[mysqld]
character-set-server=utf8 
collation-server=utf8_general_ci 
sql_mode='NO_ENGINE_SUBSTITUTION'

[mysql]
default-character-set = utf8

[mysql.server]
default-character-set = utf8


[mysqld_safe]
default-character-set = utf8


[client]
default-character-set = utf8

重啟mysql

# service mysqld restart

2. 坑

2.1. 補坑

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

開啟配置文件

# vim /etc/my.cnf (注:windows下修改的是my.ini)  

配置文件新增 [mysqld]後面任意一行新增“skip-grant-tables”用來跳過密碼驗證的過程

[mysqld]
skip-grant-tables

重啟MySQL

/etc/init.d/mysql restart(有些使用者可能需要使用/etc/init.d/mysqld restart)

重啟後修改root密碼

# mysql

mysql> use mysql;
mysql> update user set password=password("你的新密碼") where user="root";
mysql> flush privileges;
mysql> quit

到這裡root賬戶就已經重置成新的密碼了。

編輯my.cnf,去掉剛才新增的內容,然後重啟MySQL。大功告成!