[root@bogon ~]# whereis mysql
mysql: /usr/bin/mysql /usr/lib/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gzmysql
[root@bogon ~]# rpm -qa|grep mysql
mysql-community-client-5.6.26-2.el6.i686
mysql-community-release-el6-5.noarch
mysql-community-common-5.6.26-2.el6.i686
mysql-community-libs-5.6.26-2.el6.i686
mysql-community-server-5.6.26-2.el6.i686
[root@bogon ~]#linux
[root@bogon ~]# yum remove mysqlsql
刪除mysql的數據庫文件:刪除/var/llib/mysql目錄數據庫
從oracle官方網站下載linux系統對應的mysql的yum源包。vim
把yum源包上傳到linux,安裝。
[root@bogon ~]# yum localinstall mysql-community-release-el6-5.noarch.rpm
安裝成功後,咱們能夠看到/etc/yum.repos.d/目錄下增長了如下兩個文件centos
1 # ls /etc/yum.repos.d
2 mysql-community-source.repo
3 mysql-community.repo網絡
[root@bogon ~]# yum install mysql-serveroracle
1 # grep "password" /var/log/mysqld.log
2 2016-08-10T15:03:02.210317Z 1 [Note] A temporary password is generated for root@localhost: AYB(&-3Cz-rW
如今必須馬上修改密碼,否則會報錯:測試
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
修改密碼(若是在此步報錯ERROR 1819,請向下翻查看緣由及解決方法):網站
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
在修改密碼步驟,若設置的密碼爲簡單密碼,可能會出現以下錯誤:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
這一錯誤其實與validate_password_policy值的設置有關,看文末尾解決方法。
1 chkconfig --list | grep mysqld
2 chkconfig mysqld on
注意:'myuser'、'mypassword' 須要替換成實際的用戶名和密碼。 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
vim /etc/my.cnf
在[mysqld]部分添加:
character-set-server=utf8
在文件末尾新增[client]段,並在[client]段添加:
default-character-set=utf8
修改好以後重啓mysqld服務:
service mysqld restart
查看修改結果:
mysql> show variables like "%character%"; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
這一錯誤其實與validate_password_policy值的設置有關:
validate_password_policy值默認爲1,即MEDIUM,因此剛開始設置的密碼必須符合長度要求,且必須含有數字,小寫或大寫字母,特殊字符
若是咱們只是作爲測試用而不須要如此複雜的密碼,可以使用以下方式修改validate_password_policy值
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
這樣,對密碼要求就只有長度了,而密碼的最小長度由validate_password_length值決定
validate_password_length參數默認爲8,它有最小值的限制,最小值爲:
validate_password_number_count+ validate_password_special_char_count+ (2 * validate_password_mixed_case_count)
其中,validate_password_number_count指定了密碼中數字的長度,validate_password_special_char_count指定了密碼中特殊字符的長度,validate_password_mixed_case_count指定了密碼中大小字母的長度。這些參數的默認值均爲1,因此validate_password_length最小值爲4,若是顯性指定validate_password_length的值小於4,儘管不會報錯,但validate_password_length的值將設爲4
設置validate_password_length的值:
mysql> set global validate_password_length=4;
Query OK, 0 rows affected (0.00 sec)
若是修改了validate_password_number_count,validate_password_special_char_count,validate_password_mixed_case_count中任何一個值,則validate_password_length將進行動態修改。
若是沒有網絡環境可使用mysql離線安裝包來安裝。
[root@bogon mysql-rpm]# rpm -ivh mysql-community-*
安裝後,啓動服務、設置密碼、遠程受權後既可使用。