Linux 安裝mysql

1.到mysql官網下載mysql編譯好的二進制安裝包,在下載頁面Select Platform:選項選擇linux-generic,而後把頁面拉到底部,64位系統下載Linux - Generic (glibc 2.5) (x86, 64-bit),下載後文件名:mysql-5.6.33-linux-glibc2.5-x86_64.tar.gzmysql


2.解壓64位安裝包:
進入安裝包所在目錄,執行命令:tar xzvfmysql-5.6.33-linux-glibc2.5-x86_64.tar.gzlinux

3.複製解壓後的mysql目錄到系統的本地軟件目錄:sql

執行命令:cp mysql-5.6.33-linux-glibc2.5-x86_64/usr/local/mysql -r
注意:目錄結尾不要加/數據庫


4.添加系統mysql組和mysql用戶:
執行命令:groupadd mysql和useradd -r -g mysql mysqlsocket

5.安裝數據庫:
進入安裝mysql軟件目錄:執行命令 cd/usr/local/mysql
修改當前目錄擁有者爲mysql用戶:執行命令chown-R mysql:mysql ./
安裝數據庫:執行命令./scripts/mysql_install_db--user=mysql
修改當前目錄擁有者爲root用戶:執行命令chown-R root:root ./
修改當前data目錄擁有者爲mysql用戶:執行命令chown -R mysql:mysql data
到此數據庫安裝完畢ui

6.啓動mysql服務和添加開機啓動mysql服務:
添加開機啓動:執行命令cp support-files/mysql.server /etc/init.d/mysql,把啓動腳本放到開機初始化目錄
chmod +x /etc/init.d/mysql    賦予可執行權限spa

chkconfig --add mysql        添加服務
chkconfig --list            顯示服務列表
若是看到mysql的服務,而且3,4,5都是on的話則成功,若是是off,則鍵入
chkconfig --level 345 mysql onorm

 

啓動mysql服務:執行命令service mysql startserver

 

執行命令:ps -ef|grep mysql 看到mysql服務說明啓動成功。ip

7.修改mysql的root用戶密碼,root初始密碼爲空的:

執行命令:./bin/mysqladmin -u rootpassword '密碼'
若是報錯:
/usr/bin/mysqladmin: connect toserver at 'localhost' failed
error: 'Can't connect to local MySQL server through socket'/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock'exists!

(1)先中止服務:service mysql stop
(2)修改/etc/my.conf:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
If there is not currently asection called [client], add one at the bottom of the file and copy the socket=line under the [mysqld] section such as:
[client]
socket=/var/lib/mysql/mysql.sock

 


(3)執行/usr/local/mysql/bin/mysqld_safe& service mysql start
(4)無密碼root賬號登錄
/usr/bin/mysql -uroot -p 【註釋,在下面的要求你輸入密碼的時候,你不用管,直接回車鍵一敲就過去了】
Enter password:
Welcome to the MySQL monitor. Commandsend with ; or \g.
…………
Type 'help;' or '\h' for help.Type '\c' to clear the current input statement.
mysql> use mysql;
Database changed
(5) 手動update修改密碼
mysql> update user setpassword=password("新密碼") where user='root' andhost='localhost';
Query OK, 1 row affected (0.00sec)
Rows matched: 1 Changed: 1 Warnings:0
mysql> flush privileges;
Query OK, 0 rows affected (0.00sec)
mysql> quit
Bye
8.正常從新啓動mysql服務登陸 mysql -uroot -p
9.把mysql客戶端放到默認路徑:
ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql 注意:建議使用軟鏈過去,不要直接包文件複製,便於系統安裝多個版本的mysql

相關文章
相關標籤/搜索