Linux下安裝mysql

轉自: http://www.cnblogs.com/fnlingnzb-learner/p/5830622.html
Linux下安裝mysql
到mysql官網下載mysql編譯好的二進制安裝包,在下載頁面Select Platform:選項選擇linux-generic,然後把頁面拉到底部,64位系統下載Linux - Generic (glibc 2.5) (x86, 64-bit),32位系統下載Linux - Generic (glibc 2.5) (x86, 32-bit)
在這裏插入圖片描述
在這裏插入圖片描述
解壓32位安裝包:
進入安裝包所在目錄,執行命令:tar -zxvf mysql-5.6.17-linux-glibc2.5-i686.tar.gz
在這裏插入圖片描述
複製解壓後的mysql目錄到系統的本地軟件目錄:
執行命令:cp mysql-5.6.17-linux-glibc2.5-i686 /usr/local/mysql -r

注意:目錄結尾不要加/
在這裏插入圖片描述
添加系統mysql組和mysql用戶:
執行命令:groupadd mysql和useradd -r -g mysql mysql
在這裏插入圖片描述
在這裏插入圖片描述
安裝數據庫:
進入安裝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

到此數據庫安裝完畢
在這裏插入圖片描述
啓動mysql服務和添加開機啓動mysql服務:
添加開機啓動:執行命令cp support-files/mysql.server /etc/init.d/mysql,把啓動腳本放到開機初始化目錄

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

執行命令:ps -ef|grep mysql 看到mysql服務說明啓動成功,如圖
在這裏插入圖片描述
修改mysql的root用戶密碼,root初始密碼爲空的:
執行命令:./bin/mysqladmin -u root password ‘密碼’
在這裏插入圖片描述
把mysql客戶端放到默認路徑:
ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql

注意:建議使用軟鏈過去,不要直接包文件複製,便於系統安裝多個版本的mysql
在這裏插入圖片描述
以上更詳細的內容地址:http://jingyan.baidu.com/article/a378c9609eb652b3282830fd.html

注意問題:

自我感覺mysql 5.7這一系列的版本都很變態啊,不管是windows的還是Linux,安裝的時候總會出些莫名其妙的想法。當初在windows下安裝mysql的時候,年輕不懂事下了5.7版本的,結果出現了各種難以捉摸的bug,在網上查也找不到,最後發現一個同病相憐的人訴說是版本問題,裝成5.6就好了。而這次裝linux的,年少輕狂的我忘記了windows下的教訓,裝了5.7,結果一直出現各種bug,哎,還是太年輕了。希望大家能吸取教訓吧。

9.安裝完後的使用

安裝完以後,大家可以輸入mysql -uroot -p,然後enter password來進入mysql。

進去後可以使用mysql的各種語法,首先可以查看database:show databases。

Linux下mysql的卸載:

1、查找以前是否裝有mysql

命令:rpm -qa|grep -i mysql

可以看到mysql的兩個包:

mysql-4.1.12-3.RHEL4.1

mysqlclient10-3.23.58-4.RHEL4.1

2、刪除mysql

刪除命令:rpm -e --nodeps 包名

( rpm -ev mysql-4.1.12-3.RHEL4.1 )

3、刪除老版本mysql的開發頭文件和庫

檢查各個mysql文件夾是否刪除乾淨

find / -name mysql

結果如下:

/var/lib/mysql

/usr/local/mysql

/usr/lib/mysql

/usr/include/mysql

命令:

rm -fr /usr/lib/mysql

rm -fr /usr/include/mysql

注意:卸載後/var/lib/mysql中的數據及/etc/my.cnf不會刪除,如果確定沒用後就手工刪除

rm -f /etc/my.cnf

rm -fr /var/lib/mysql

4.刪除mysql用戶及用戶組

userdel mysql

groupdel mysql

Linux下創建和刪除軟鏈接:

1.先建立一個軟連接

複製代碼
1 [[email protected] test]# ls -il
2 總計 0
3 1491138 -rw-r–r– 1 root root 48 07-14 14:17 file1
4 1491139 -rw-r–r– 2 root root 0 07-14 14:17 file2
5 1491139 -rw-r–r– 2 root root 0 07-14 14:17 file2hand
6 #建立file1和file1soft軟連接
7 [[email protected] test]# ln -s file1 file1soft
8 [[email protected] test]# ls -il
9 總計 0
10 1491138 -rw-r–r– 1 root root 48 07-14 14:17 file1
11 1491140 lrwxrwxrwx 1 root root 5 07-14 14:24 file1soft -> file1
12 1491139 -rw-r–r– 2 root root 0 07-14 14:17 file2
13 1491139 -rw-r–r– 2 root root 0 07-14 14:17 file2hand
複製代碼
其中,ln -s file1 filesoft 中的file1就是源文件,file1soft就是目標鏈接文件名,其作用是當進入filesoft目錄,實際上是鏈接進入了file1目錄

2.刪除上面建立的軟連接

複製代碼
1 [[email protected] test]# ls -il
2 總計 0
3 1491138 -rw-r–r– 1 root root 0 07-14 14:17 file1
4 1491140 lrwxrwxrwx 1 root root 5 07-14 14:24 file1soft -> file1
5 1491139 -rw-r–r– 2 root root 0 07-14 14:17 file2
6 1491139 -rw-r–r– 2 root root 0 07-14 14:17 file2hand
7 #刪除軟連接
8 [[email protected] test]# rm -rf file1soft
9 [[email protected] test]# ls -il
10 總計 0
11 1491138 -rw-r–r– 1 root root 0 07-14 14:17 file1
12 1491139 -rw-r–r– 2 root root 0 07-14 14:17 file2
13 1491139 -rw-r–r– 2 root root 0 07-14 14:17 file2hand
複製代碼

啓動mysql時顯示:/tmp/mysql.sock 不存在的解決方法
複製代碼
1 [root@localhost mysql]# bin/mysqladmin -u root password root
2 bin/mysqladmin: connect to server at ‘localhost’ failed
3 error: ‘Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)’
4 Check that mysqld is running and that the socket: ‘/tmp/mysql.sock’ exists!
5 [root@localhost mysql]# bin/mysql -u root -p
6 Enter password:
7 ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
8 分析:是/tmp/mysql.sock 不存在
複製代碼
由於搜索的mysql.sock路徑是在/tmp下,而mysql安裝的mysql.sock在/var/lib/mysql下,所以選擇建立符號(軟)連接:

複製代碼
1 # ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
2 # bin/mysql -u root
3 Welcome to the MySQL monitor. Commands end with ; or g.
4 Your MySQL connection id is 1
5 Server version: 5.0.45 MySQL Community Server (GPL)
6 Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.
7 mysql>
複製代碼

安裝mysql報錯:FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:Data::Dumper
解決方法 :安裝autoconf庫
命令:yum-y install autoconf //此包安裝時會安裝Data:Dumper模塊

Centos 7以上啓動mysql報錯:Starting MySQL. ERROR! The server quit without updating PID file (/var/lib/mysql/bj-dev2.pid).
1、可能是/usr/local/mysql/data/mysql.pid文件沒有寫的權限
解決方法 :給予權限,執行 “chown -R mysql:mysql /var/data” “chmod -R 755 /usr/local/mysql/data” 然後重新啓動mysqld!

2、可能進程裏已經存在mysql進程
解決方法:用命令“ps -ef|grep mysqld”查看是否有mysqld進程,如果有使用“kill -9 進程號”殺死,然後重新啓動mysqld!

3、可能是第二次在機器上安裝mysql,有殘餘數據影響了服務的啓動。
解決方法:去mysql的數據目錄/data看看,如果存在mysql-bin.index,就趕快把它刪除掉吧,它就是罪魁禍首了。

4、mysql在啓動時沒有指定配置文件時會使用/etc/my.cnf配置文件,請打開這個文件查看在[mysqld]節下有沒有指定數據目錄(datadir)。
解決方法:請在[mysqld]下設置這一行:datadir = /usr/local/mysql/data

5、skip-federated字段問題
解決方法:檢查一下/etc/my.cnf文件中有沒有沒被註釋掉的skip-federated字段,如果有就立即註釋掉吧。

6、錯誤日誌目錄不存在。(本人是這個方法解決的)
解決方法:使用“chown” “chmod”命令賦予mysql所有者及權限

7、selinux惹的禍,如果是centos系統,默認會開啓selinux
解決方法:關閉它,打開/etc/selinux/config,把SELINUX=enforcing改爲SELINUX=disabled後存盤退出重啓機器試試。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章