系統版本:centos6.5 64位作業系統
安裝環境:使用shell 指令
工具:WIMscp 和 putty
此次安裝在桌面環境下,使用shell指令進行安裝,下載下傳安裝包為:
MySQL-5.6.25-1.linux_glibc2.5.x86_64.rpm-bundle
以下是按照步驟。如果有一些包的名稱不一緻,請忽略。
a. 檢查MySQL及相關RPM包,是否安裝,如果有安裝,則移除(rpm –e 名稱 #)
[[email protected] ~]# rpm -qa | grep -i mysql
mysql-libs-5.1.66-2.el6_3.x86_64
[[email protected] ~]# yum -y remove mysql-libs*
b. 選擇Linux對應的RPM包,如下:
[[email protected] rpm]# ll
total 74364
-rw-r–r–. 1 root root 18442536 Dec 11 20:19 MySQL-client-5.6.15-1.el6.x86_64.rpm
-rw-r–r–. 1 root root 3340660 Dec 11 20:06 MySQL-devel-5.6.15-1.el6.x86_64.rpm
-rw-r–r–. 1 root root 54360600 Dec 11 20:03 MySQL-server-5.6.15-1.el6.x86_64.rpm
這裡,我是直接把MySQL-5.6.25-1.linux_glibc2.5.x86_64.rpm-bundle用WIMscp工具複制到linux服務端的。
複制過去後,使用解壓指令:
tar –xvf file.tar 解壓 tar包
c. 安裝MySQL
[[email protected] rpm]# rpm -ivh MySQL-server-5.6.15-1.el6.x86_64.rpm
[[email protected] rpm]# rpm -ivh MySQL-devel-5.6.15-1.el6.x86_64.rpm
[[email protected] rpm]# rpm -ivh MySQL-client-5.6.15-1.el6.x86_64.rpm
複制配置檔案位置(這一步我沒做)
[[email protected] rpm]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf
這裡遇到一個問題:CentOS下安裝官方RPM包的MySQL後,/etc/目錄下找不到my.cnf
我的解決方法是直接在/etc/目錄下建立一個空的檔案。
touch my.cnf
d. 初始化MySQL及設定密碼
[[email protected] rpm]# /usr/bin/mysql_install_db
[[email protected] rpm]# service mysql start
[[email protected] rpm]# cat /root/.mysql_secret #檢視root賬号密碼
# The random password set for the root user at Wed Dec 11 23:32:50 2013 (local time): qKTaFZnl
[[email protected] ~]# mysql -uroot –pqKTaFZnl
mysql> SET PASSWORD = PASSWORD('123456');#設定密碼為123456
mysql> exit
[[email protected] ~]# mysql -uroot -p123456
e. 遠端登陸使用者設定
mysql> use mysql;
mysql> select host,user,password from user;
mysql> update user set password=password('123456') where user='root';
mysql> update user set host='%' where user='root' and host='localhost';
mysql> flush privileges;
mysql> exit
f. 設定開機自啟動
[[email protected] ~]# chkconfig mysql on
[[email protected] ~]# chkconfig –list | grep mysql
mysql 0:off 1:off 2:on3:on4:on5:on6:off
g. MySQL的預設安裝位置
/var/lib/mysql/ #資料庫目錄
/usr/share/mysql #配置檔案目錄
/usr/bin #相關指令目錄
/etc/init.d/mysql #啟動腳本
h. 修改字元集和資料存儲路徑
配置/etc/my.cnf檔案,修改資料存放路徑、mysql.sock路徑以及預設編碼utf-8.
[html] view plaincopy在CODE上檢視代碼片派生到我的代碼片
[client]
password= 123456
port= 3306
default-character-set=utf8
[mysqld]
port= 3306
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
#(注意linux下mysql安裝完後是預設:表名區分大小寫,列名不區分大小寫; 0:區分大小寫,1:不區分大小寫)
lower_case_table_names=1
#(設定最大連接配接數,預設為 151,MySQL伺服器允許的最大連接配接數16384; )
max_connections=1000
[mysql]
default-character-set = utf8
可檢視字元集
[html] view plaincopy
show variables like '%collation%';
show variables like '%char%';
I.如果想遠端連接配接登入mysql則需要:授權,并關閉防火牆。
1.授權;在服務端進入mysql,輸入以下指令
[sql] view plaincopy
[GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '這裡是你的密碼' WITH GRANT OPTION;]
OR
[sql] view plaincopy
[GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '' WITH GRANT OPTION;]
差別在于通路時是否需要寫密碼。
這句的作用是将所有的使用者名,都設定能遠端通路該mysql中所有的表,如果不想都放開,可以根據這個規則,來設定.grant 權限1,權限2,…權限n on 資料庫名.表名 to使用者名@使用者位址 identified by‘密碼’.
2.關閉防火牆
[html] view plaincopy
service iptables stop 關閉指令
chkconfig iptables off 永久關閉防火牆
兩個指令同時運作,運作完成後檢視防火牆關閉狀态
[html] view plaincopy
service iptables status
到此,mysql就安裝完成并配置成功了
題外問題:
--------- -- 添加使用者
-- grant all on *.* to 'devuser'@'localhost' identified by 'dev#1234' with grant option;
-- FLUSH PRIVILEGES;
-- -- 給使用者賦權限
-- grant 權限1,權限2,…權限n on 資料庫名稱.表名稱 to 使用者名@使用者位址 identified by ‘連接配接密碼’;
-- GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON my_crm.* TO [email protected]'%' identified by 'dev'; ;
-- FLUSH PRIVILEGES;
-- 驗證
-- select * from mysql.`user`