https://www.cnblogs.com/xxoome/p/5864912.html
linux版本:CentOS7 64位
1巷嚣、下載安裝包“mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz”
# 安裝依賴
yum -y install perl perl-devel autoconf libaio
2、把下載的安裝包移動到/usr/local/下。
3欺劳、解壓 tar zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
4这敬、復(fù)制解壓后的mysql目錄到系統(tǒng)的本地軟件目錄
cp mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql -r
5、添加系統(tǒng)mysql組和mysql用戶
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
注意:Because the user is required only for ownership purposes, not login purposes, the useradd command uses the -r and -s /bin/false options to create a user that does not have login permissions to your server host. Omit these options if your useradd does not support them.
6媳叨、進(jìn)入安裝mysql軟件目錄腥光,修改目錄擁有者為mysql用戶
cd mysql/
chown -R mysql:mysql ./
7、安裝數(shù)據(jù)庫糊秆,此處可能出現(xiàn)錯誤武福。
./scripts/mysql_install_db --user=mysql
FATAL ERROR: please install the following Perl modules before executing scripts/mysql_install_db:
Data::Dumper
#解決方法:
yum install -y perl-Data-Dumper
8、修改當(dāng)前目錄擁有者為root用戶
chown -R root:root ./
9痘番、修改當(dāng)前data目錄擁有者為mysql用戶
chown -R mysql:mysql data
============== 到此數(shù)據(jù)庫安裝完畢 =============
10捉片、添加mysql服務(wù)開機(jī)自啟動
添加開機(jī)啟動平痰,把啟動腳本放到開機(jī)初始化目錄。
復(fù)制代碼
cp support-files/mysql.server /etc/init.d/mysql
# 賦予可執(zhí)行權(quán)限
chmod +x /etc/init.d/mysql
# 添加服務(wù)
chkconfig --add mysql
# 顯示服務(wù)列表
chkconfig --list
復(fù)制代碼
如果看到mysql的服務(wù)伍纫,并且3,4,5都是on的話則成功宗雇,如果是off,則執(zhí)行
chkconfig --level 345 mysql on
11莹规、啟動mysql服務(wù)
#創(chuàng)建缺少的文件夾
mkdir /var/log/mariadb
service mysql start
正常提示信息:Starting MySQL. SUCCESS!
12赔蒲、把mysql客戶端放到默認(rèn)路徑
ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
注意:建議使用軟鏈過去,不要直接包文件復(fù)制访惜,便于系統(tǒng)安裝多個版本的mysql
=================== 這是分割線 ==================
通過使用 mysql -uroot -p 連接數(shù)據(jù)庫(默認(rèn)數(shù)據(jù)庫的root用戶沒有密碼嘹履,這個需要設(shè)置一個密碼)。
錯誤信息:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
解決方法:打開/etc/my.cnf,看看里面配置的socket位置是什么目錄债热±担“socket=/var/lib/mysql/mysql.sock”
路徑和“/tmp/mysql.sock”不一致。建立一個軟連接:ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
到這里任務(wù)算是完成了窒篱。之后就可以創(chuàng)建數(shù)據(jù)庫用戶焕刮,然后使用數(shù)據(jù)庫了。
權(quán)限控制
1墙杯、去除匿名用戶
# 測試匿名用戶登錄
mysql -ux3
可以看到匿名用戶可以登錄配并,具有information_schema和test庫的相關(guān)權(quán)限。
# 刪除匿名用戶高镐,使用root用戶登錄數(shù)據(jù)庫
delete from mysql.user where User='';
flush privileges;
遠(yuǎn)程訪問控制
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '9ss7' WITH GRANT OPTION;