mysql5.6-GA版是mysql5.6的最終穩定版本,故選擇該版本做爲教程目標進行安裝。node
如下爲安裝步驟:mysql
一、先查看系統是否存在已有的mysqllinux
rpm -qa | grep mysql
二、刪除已存在的mysqlsql
rpm -e mysql --nodeps
三、下載並解壓mysql包bash
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-5.6.31-1.linux_glibc2.5.x86_64.rpm-bundle.tar tar -zxvf MySQL-5.6.31-1.linux_glibc2.5.x86_64.rpm-bundle.tar
四、依次安裝tar包中的三個包
a.MySQL-client-5.6.31-1.linux_glibc2.5.x86_64.rpm
b.MySQL-server-5.6.31-1.linux_glibc2.5.x86_64.rpm
c.MySQL-devel-5.6.31-1.linux_glibc2.5.x86_64.rpm
五、rpm安裝,mysql會生成root用戶的隨機密碼,在/root下socket
cat /root/.mysql_secret
六、使用此密碼進入mysql控制檯tcp
mysql -u root -p
七、修改root密碼ide
mysql>set password for 'root'@'localhost'=password('newpasswd');
八、開啓mysql遠程訪問code
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option; flush privileges; exit;
9.配置mysql配置文件
a.從/usr/share/mysql/處,拷貝my-default.cnf到/etc:server
cp /usr/share/mysql/my-default.cnf /etc/my.cnf
b.修改相應配置(如中文亂碼等),如下是簡單的配置
[mysqld] port = 3306 character_set_server=utf8 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql symbolic-links=0 max_allowed_packet = 10M slave_max_allowed_packet = 10M [mysqld_safe] default-character-set = utf8 [client] port = 3306 socket = /var/lib/mysql/mysql.sock default-character-set=utf8 [mysql.server] default-character-set = utf8 [mysql] no-auto-rehash default-character-set = utf8
c.重啓mysql服務
10.開啓防火牆3306端口
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT