Linux中必備常用支持庫(kù)的安裝(CentOS-*)
在CentOS安裝軟件的時(shí)候腮敌,可能缺少一部分支持庫(kù),而報(bào)錯(cuò)注竿。這里首先安裝系統(tǒng)常用的支持庫(kù)辰妙。那么在安裝的時(shí)候就會(huì)減少很多的錯(cuò)誤的出現(xiàn)。
#????yum install -y gcc gdb strace gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs patch e2fsprogs-devel krb5-devel libidn libidn-devel openldap-devel nss_ldap openldap-clients openldap-servers libevent-devel libevent uuid-devel uuid mysql-devel
MYSQL
?檢查是否安裝了MySQL組件仆抵。
#????rpm -qa | grep -i mysql
通過(guò)yum方式卸載mysql及相關(guān)組件?
#????yum remove mysql*
==============================================================================
二跟继、下載MySQL源安裝,MySQL-devel-5.6.23-1.linux_glibc2.5
1镣丑、下載mysql源安裝包
shell>????wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
2舔糖、 安裝mysql源
shell>????yum localinstall mysql57-community-release-el7-8.noarch.rpm
3、檢查mysql源是否安裝成功
shell>????yum repolist enabled | grep "mysql.*-community.*"
看到上圖所示表示安裝成功传轰。
4剩盒、可以更改MySQL版本,不更改則默認(rèn)安裝MySQL最新版本慨蛙,建議安裝最新版
可以修改vim /etc/yum.repos.d/mysql-community.repo源辽聊,改變默認(rèn)安裝的mysql版本。比如要安裝5.6版本期贫,將5.7源的enabled=1改成enabled=0跟匆。然后再將5.6源的enabled=0改成enabled=1即可。改完之后的效果如下所示:?
5通砍、安裝MySQL
shell>????yum install mysql-community-server
6玛臂、啟動(dòng)MySQL服務(wù)
shell>????systemctl start mysqld
或
shell>????service mysqld restart
關(guān)閉MySQL
shell>????systemctl stop mysqld
或
shell>????service mysqld stop
查看MySQL的啟動(dòng)狀態(tài)
shell>????systemctl status mysqld
或
shell>????service mysqld status
● mysqld.service - MySQL Server
?? Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
?? Active: active (running) since 五 2016-06-24 04:37:37 CST; 35min ago
Main PID: 2888 (mysqld)
?? CGroup: /system.slice/mysqld.service
?????????? └─2888 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
6月 24 04:37:36 localhost.localdomain systemd[1]: Starting MySQL Server...
6月 24 04:37:37 localhost.localdomain systemd[1]: Started MySQL Server.
4、開(kāi)機(jī)啟動(dòng)
shell>????systemctl enable mysqld
shell>????systemctl daemon-reload
5封孙、修改root本地登錄密碼
mysql安裝完成之后迹冤,在/var/log/mysqld.log文件中給root生成了一個(gè)默認(rèn)密碼。通過(guò)下面的方式找到root默認(rèn)密碼虎忌,然后登錄mysql進(jìn)行修改:
shell>????grep 'temporary password' /var/log/mysqld.log
如果找不到密碼說(shuō)明密碼默認(rèn)為空泡徙,則直接:
shell>????mysql ? ?######可以進(jìn)入MySQL
或
shell>????mysql -uroot -p
Enter password: (回車(chē))
更新密碼
mysql>????ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
或
mysql>????set password for 'root'@'localhost'=password('root');
刷新立即生效
mysql>????flush?privileges;
注意:mysql5.7默認(rèn)安裝了密碼安全檢查插件(validate_password),默認(rèn)密碼檢查策略要求密碼必須包含:大小寫(xiě)字母膜蠢、數(shù)字和特殊符號(hào)堪藐,并且長(zhǎng)度不能少于8位莉兰。否則會(huì)提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements錯(cuò)誤,如下圖所示:?
ERROR 3009 (HY000): Column count of mysql.user is wrong. Expected 45, found 43. Created with MySQL 5
錯(cuò)誤是由于你曾經(jīng)升級(jí)過(guò)數(shù)據(jù)庫(kù)礁竞,升級(jí)完后沒(méi)有使用
mysql_upgrade升級(jí)數(shù)據(jù)結(jié)構(gòu)造成的糖荒,解決辦法:使用mysql_upgrade命令?
root@localhost ~]# ????mysql_upgrade -u root -p
6、重啟MySQL
shell>????service mysqld restart
7模捂、通過(guò)msyql環(huán)境變量可以查看密碼策略的相關(guān)信息:
mysql>????show variables like '%password%';
validate_password_policy:密碼策略捶朵,默認(rèn)為MEDIUM策略?
validate_password_dictionary_file:密碼策略文件,策略為STRONG才需要?
validate_password_length:密碼最少長(zhǎng)度?
validate_password_mixed_case_count:大小寫(xiě)字符長(zhǎng)度狂男,至少1個(gè)?
validate_password_number_count :數(shù)字至少1個(gè)?
validate_password_special_char_count:特殊字符至少1個(gè)?
上述參數(shù)是默認(rèn)策略MEDIUM的密碼檢查規(guī)則泉孩。
共有以下幾種密碼策略:
策略檢查規(guī)則
0 or LOWLength
1 or MEDIUMLength; numeric, lowercase/uppercase, and special characters
2 or STRONGLength; numeric, lowercase/uppercase, and special characters; dictionary file
MySQL官網(wǎng)密碼策略詳細(xì)說(shuō)明:http://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html#sysvar_validate_password_policy
修改密碼策略
在/etc/my.cnf文件添加validate_password_policy配置,指定密碼策略
# 選擇0(LOW)并淋,1(MEDIUM)寓搬,2(STRONG)其中一種,選擇2需要提供密碼字典文件
validate_password_policy=0
如果不需要密碼策略县耽,添加my.cnf文件中添加如下配置禁用即可:
validate_password = off
重新啟動(dòng)mysql服務(wù)使配置生效:
#????systemctl restart mysqld
8句喷、添加遠(yuǎn)程登錄用戶
默認(rèn)只允許root帳戶在本地登錄,如果要在其它機(jī)器上連接mysql兔毙,必須修改root允許遠(yuǎn)程連接唾琼,或者添加一個(gè)允許遠(yuǎn)程連接的帳戶,為了安全起見(jiàn)澎剥,我添加一個(gè)新的帳戶:
mysql>????GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密碼' WITH GRANT OPTION;
mysql>????flush privileges;? ? ?#立即生效锡溯。
9、配置默認(rèn)編碼為utf8
修改/etc/my.cnf配置文件哑姚,在[mysqld]下添加編碼配置祭饭,如下所示:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
重新啟動(dòng)mysql服務(wù),查看數(shù)據(jù)庫(kù)默認(rèn)編碼如下所示:?
mysql>????show variables like '%character%';
默認(rèn)配置文件路徑:?
配置文件:/etc/my.cnf?
錯(cuò)誤日志文件:/var/log/mysqld.log?
服務(wù)啟動(dòng)腳本:/usr/lib/systemd/system/mysqld.service?
socket文件:/var/run/mysqld/mysqld.pid
數(shù)據(jù)庫(kù)安裝目錄:/var/lib/mysql/mysql
#????mysql -uroot -proot
>????set global general_log=on;
>????show variables like 'general_log_file';
訪問(wèn)日志記錄:/var/lib/mysql/VM_13_166_centos.log?