通過uname -a或lsb_release -a 查看版本信息 ,確定linux的發行版是debian還是ubuntu。
root@suepc:/usr/local# uname -a
Linux suepc 3.13.0-129-generic #178-Ubuntu SMP Fri Aug 11 12:48:20 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
根據對應的版本下載mysql
mysql的下載地址:https://dev.mysql.com/downloads/file/?id=471390
本文以 mysql-server_5.7.19-1ubuntu14.04_amd64.deb-bundle.tar 為例。
1. )更新源
sudo apt-get update
sudo apt-get upgrade
2.)將mysql包放在usr的local目錄下
cd /usr/local/
sudo cp ~/Download/mysql-server_5.7.19-1ubuntu14.04_amd64.deb-bundle.tar .
3.)切換到root用戶下,並輸入密碼
su root
******
4.)在當前目錄新建一個將mysql包並將mysql-server_5.7.19-1ubuntu14.04_amd64.deb-bundle.tar解壓
mkdir mysql
tar -xvf mysql-server_5.7.19-1ubuntu14.04_amd64.deb-bundle.tar
5.)解壓好后一共有11個壓縮包如下:
libmysqlclient20_5.7.19-1ubuntu14.04_amd64.deb mysql-common_5.7.19-1ubuntu14.04_amd64.deb mysql-community-test_5.7.19-1ubuntu14.04_amd64.deb
libmysqlclient-dev_5.7.19-1ubuntu14.04_amd64.deb mysql-community-client_5.7.19-1ubuntu14.04_amd64.deb mysql-server_5.7.19-1ubuntu14.04_amd64.deb
libmysqld-dev_5.7.19-1ubuntu14.04_amd64.deb mysql-community-server_5.7.19-1ubuntu14.04_amd64.deb mysql-testsuite_5.7.19-1ubuntu14.04_amd64.deb
mysql-client_5.7.19-1ubuntu14.04_amd64.deb mysql-community-source_5.7.19-1ubuntu14.04_amd64.deb
6.)因為包與包中間存在依賴關系,這里安裝有個先后順序。這里用sudo dpkg -i [包名]命令逐個安裝。
我的安裝的順序是:
1.mysql-common_5.7.19-1ubuntu14.04_amd64.deb
2.libmysqlclient20_5.7.19-1ubuntu14.04_amd64.deb
3.libmysqlclient-dev_5.7.19-1ubuntu14.04_amd64.deb
4.libmysqld-dev_5.7.19-1ubuntu14.04_amd64.deb
7.)需要再安裝一個依賴包叫libaio1,命令為 sudo apt-get install libaio1
8.)繼續:
5.mysql-community-client_5.7.19-1ubuntu14.04_amd64.deb
6.mysql-client_5.7.19-1ubuntu14.04_amd64.deb
7.mysql-community-source_5.7.19-1ubuntu14.04_amd64.deb
9.)這里需要再安裝一個依賴包叫libmecab2,安裝好后,繼續安裝最后一個:
8.mysql-community-server_5.7.19-1ubuntu14.04_amd64.deb
以上操作在root用戶下進行,安裝完成后MYSQL是默認啟動的 安裝過程中需要設置數據庫密碼。
到這里,所有的已經安裝完畢。輸入mysql -u root -p可以登陸數據庫了。
10.停止mysql
service mysql stop
11.啟動mysql
service mysql start
12.進入mysql登陸數據庫
mysql -u root -p
QA:遠程工具報10061錯誤
默認情況下MySQL不允許這些工具遠程連接的,你可以找到/etc/mysql/my.cnf這個文件,將bind-address=127.0.0.1改為 bind-address=0.0.0.0 或將其注釋掉
執行GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '1qaz2wsx' WITH GRANT OPTION;
重啟mysql即可。
---------------------------------------------------------------------------------------------------------
設置數據庫默認字符集:
vi /etc/mysql/my.cnf
增加:
[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8
