Linux下安裝MySQL----來自簡書(挺好的)
阿新 • • 發佈:2019-02-16
col 刪除 sql mysql defined cte nts conf mysql5.7 pan
D_C
關註
2016.07.06 21:55*
字數 509
閱讀 26070評論 6喜歡 24贊賞 1
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Linux下安裝MySQL
環境:
1、操作系統:CentOS release 6.8 (Final)
2、安裝版本: mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz
3、下載地址:http://dev.mysql.com/downloads/mysql/
4、下載說明:上邊的下載地址是最新版的,如果想下載老版本可以點擊頁面中的超鏈接“Looking for previous GA versions?”
5、特殊說明:Linux下MySQL5.6與MySQL5.7安裝方法略有不同,本文以5.6為主
安裝步驟
0、卸載老版本MySQL
查找並刪除mysql有關的文件
find / -name mysql
rm -rf 上邊查找到的路徑,多個路徑用空格隔開
#或者下邊一條命令即可
find / -name mysql|xargs rm -rf
![技術分享圖片](http://upload-images.jianshu.io/upload_images/1899977-305617e34955e4d3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
1、在安裝包存放目錄下執行命令解壓文件:
tar -zxvf mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz
![技術分享圖片](http://upload-images.jianshu.io/upload_images/1899977-f8b6174388c8531d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
2、刪除安裝包,重命名解壓後的文件
rm -f mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz mv mysql-5.6.31-linux-glibc2.5-x86_64/ mysql
![技術分享圖片](http://upload-images.jianshu.io/upload_images/1899977-7c5b2ca42cf623e1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
3、添加mysql用戶組和mysql用戶
先檢查是否有mysql用戶組和mysql用戶
groups mysql
![技術分享圖片](http://upload-images.jianshu.io/upload_images/1899977-cc398fb960e0cb76.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/443/format/webp)
若無,則添加;
groupadd mysql
useradd -r -g mysql mysql
![技術分享圖片](http://upload-images.jianshu.io/upload_images/1899977-f80edc428a9e61cf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/591/format/webp)
若有,則跳過;
![技術分享圖片](http://upload-images.jianshu.io/upload_images/1899977-6aee55a3221c0446.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/426/format/webp)
4、進入mysql目錄更改權限
cd mysql/
chown -R mysql:mysql ./
![技術分享圖片](http://upload-images.jianshu.io/upload_images/1899977-ad018015ea413b53.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/771/format/webp)
5、執行安裝腳本
./scripts/mysql_install_db --user=mysql
![技術分享圖片](http://upload-images.jianshu.io/upload_images/1899977-e07b0b2383d9fc81.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
安裝完之後修改當前目錄擁有者為root用戶,修改data目錄擁有者為mysql
chown -R root:root ./
chown -R mysql:mysql data
![技術分享圖片](http://upload-images.jianshu.io/upload_images/1899977-4e2b1c5c2fd75d24.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/877/format/webp)
6、更改mysql密碼
上一步安裝腳本執行輸出的日誌中告訴我們如何更改密碼了
![技術分享圖片](http://upload-images.jianshu.io/upload_images/1899977-ccd379696682e6c6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/855/format/webp)
但是如果直接執行這兩條命令就會報錯
![技術分享圖片](http://upload-images.jianshu.io/upload_images/1899977-151811b1ccfd6b75.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/950/format/webp)
因為這時還沒有啟動mysql,這算是一個坑。啟動方法如下:
./support-files/mysql.server start
![技術分享圖片](http://upload-images.jianshu.io/upload_images/1899977-31eacd5fca58b5b5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/765/format/webp)
如果MySQL啟動報錯,則可能是已經存在MySQL進程,殺掉即可
ps aux|grep mysql
kill -9 上邊的進程號
#或者下邊一條命令即可殺掉所有MySQL進程
ps aux|grep mysql|awk ‘{print $2}‘|xargs kill -9
![技術分享圖片](http://upload-images.jianshu.io/upload_images/1899977-6572db71fdf5faa7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
殺掉後再啟動即可。
![技術分享圖片](http://upload-images.jianshu.io/upload_images/1899977-f417bdc69058de74.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/794/format/webp)
MySQL啟動之後再執行如下命令更改密碼:
./bin/mysqladmin -u root -h localhost.localdomain password ‘root‘
![技術分享圖片](http://upload-images.jianshu.io/upload_images/1899977-d1a1c4478febf199.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
密碼更改後即可登錄MySQL
./bin/mysql -h127.0.0.1 -uroot -proot
![技術分享圖片](http://upload-images.jianshu.io/upload_images/1899977-c22b674ff3f96009.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/939/format/webp)
登錄之後將其他用戶的密碼也可改為root
update mysql.user set password=password(‘root‘) where user=‘root‘;
flush privileges;
![技術分享圖片](http://upload-images.jianshu.io/upload_images/1899977-010a473ab72f59fc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/992/format/webp)
7、增加遠程登錄權限
上一步即可本地登錄,但遠程登錄會報錯
![技術分享圖片](http://upload-images.jianshu.io/upload_images/1899977-2185d688960a5413.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/502/format/webp)
為解決這一問題,需要本地登陸MySQL後執行如下命令
grant all privileges on *.* to root@‘%‘ identified by ‘root‘;
flush privileges;
執行之後即可遠程登錄
8、將MySQL加入Service系統服務
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
service mysqld restart
service mysqld status
9、配置my.cnf
vim my.cnf
#添加以下兩條語句並保存退出
character-set-server=utf8
lower_case_table_names=1
max_allowed_packet=100M
配置好之後,重啟mysqld服務
Linux下安裝MySQL----來自簡書(挺好的)