1、檢查系統中是否已經安裝過mysql。mysql
rpm -qa | grep mysqlsql
若是存在,則須要刪除。
yum -y remove mysql*數據庫
繼續檢查一下是否還存在mysql
rpm -qa | grep -i mysqlapp
2、下載rpm包。socket
須要下載:
MySQL-client-5.6.15-1.el6.x86_64.rpm
MySQL-devel-5.6.15-1.el6.x86_64.rpm
MySQL-server-5.6.15-1.el6.x86_64.rpm
逐一執行命令:
wget http://cdn.mysql.com/archives/mysql-5.6/MySQL-client-5.6.15-1.el6.x86_64.rpm編碼
wget http://cdn.mysql.com/archives/mysql-5.6/MySQL-devel-5.6.15-1.el6.x86_64.rpmspa
wget http://cdn.mysql.com/archives/mysql-5.6/MySQL-server-5.6.15-1.el6.x86_64.rpm.net
3、依次安裝rest
rpm -ivh MySQL-server-5.6.15-1.el6.x86_64.rpmcdn
rpm -ivh MySQL-devel-5.6.15-1.el6.x86_64.rpm
rpm -ivh MySQL-client-5.6.15-1.el6.x86_64.rpm
4、 初始化MySQL及設置密碼
cp /usr/share/mysql/my-default.cnf /etc/my.cnf
cat /root/.mysql_secret 記錄最後的密碼
mysql -p ---輸入記錄的密碼,便可登陸mysql。
set password for 'root'@'localhost' =password('新密碼');
flush privileges; //刷新權限設置
5、配置數據庫編碼格式
登陸MySQL查看用SHOW VARIABLES LIKE 'character%';下字符集,顯示以下:
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
character_set_database和character_set_server的默認字符集仍是latin1。
最簡單的完美修改方法,修改mysql的my.cnf文件中的字符集鍵值(注意配置的字段細節):
一、在[client]字段里加入default-character-set=utf8,以下:
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set=utf8
二、在[mysqld]字段里加入character-set-server=utf8,以下:
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
character-set-server=utf8
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
三、在[mysql]字段里加入default-character-set=utf8,以下:
[mysql]
no-auto-rehash
default-character-set=utf8
修改完成後,service mysql restart重啓mysql服務就生效,並flush privileges; //刷新權限設置。
使用SHOW VARIABLES LIKE ‘character%’;查看,發現數據庫編碼全已改爲utf8。 +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+