記一次Centos6 安裝mysql8全過程;html
rpm -qa|grep mysql
複製代碼
[root@10 /]# rpm -qa|grep mysql mysql-community-client-8.0.21-1.el6.x86_64 mysql80-community-release-el6-1.noarch mysql-community-server-8.0.21-1.el6.x86_64 mysql-community-common-8.0.21-1.el6.x86_64 mysql-community-libs-8.0.21-1.el6.x86_64 複製代碼
若是結果如上,須要一個個卸載;node
rpm -e --nodeps mysql-community-client-8.0.21-1.el6.x86_64 rpm -e --nodeps mysql80-community-release-el6-1.noarch rpm -e --nodeps mysql-community-server-8.0.21-1.el6.x86_64 rpm -e --nodeps mysql-community-common-8.0.21-1.el6.x86_64 rpm -e --nodeps mysql-community-libs-8.0.21-1.el6.x86_64 複製代碼
cd /opt wget https://dev.mysql.com/get/mysql80-community-release-el6-1.noarch.rpm 複製代碼
rpm -ivh mysql80-community-release-el6-1.noarch.rpm
複製代碼
yum install mysql-server
複製代碼
執行這兩行命令,若是網絡快的話,很快就安裝完成了。mysql
mysqladmin -V
複製代碼
到此就安裝成功了。web
# 啓動
service mysqld start # 檢查狀態 service mysqld status # 關閉 service mysqld stop # 重啓 service mysqld restart 複製代碼
使用該命令啓動mysql。sql
默認有個隨機密碼:數據庫
cat /var/log/mysqld.log
複製代碼
使用該密碼登陸vim
mysql -u root -p
複製代碼
第一次操做數據庫的同窗,必定要記得每一個SQL執行語句後面都須要以分號結尾。bash
隨機密碼不容易記,因此須要改一個方便記憶的密碼;網絡
mysql> use mysql;
複製代碼
查看當前用戶session
mysql> select user,host from user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| root | localhost |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
+------------------+-----------+
4 rows in set (0.01 sec)
複製代碼
查看端口
mysql> show global variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0.05 sec)
複製代碼
查看密碼強度
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+
複製代碼
關於 mysql 密碼策略相關參數;
1)、validate_password_length 固定密碼的總長度;
2)、validate_password_dictionary_file 指定密碼驗證的文件路徑;
3)、validate_password_mixed_case_count 整個密碼中至少要包含大/小寫字母的總個數;
4)、validate_password_number_count 整個密碼中至少要包含阿拉伯數字的個數;
5)、validate_password_policy 指定密碼的強度驗證等級,默認爲 MEDIUM;
關於 validate_password_policy 的取值:
0/LOW:只驗證長度;
1/MEDIUM:驗證長度、數字、大小寫、特殊字符;
2/STRONG:驗證長度、數字、大小寫、特殊字符、字典文件;
6)、validate_password_special_char_count 整個密碼中至少要包含特殊字符的個數
複製代碼
默認是MEDIUM密碼強度等級,算是通常嚴格的;如圖有嚴格的要求;
若是你想設置一個簡單的密碼,把validate_password_policy等級改成low便可。
set global validate_password_policy=LOW;
複製代碼
改密碼
alter user 'root'@'localhost' IDENTIFIED BY 'Alex@666';
複製代碼
重啓服務
service mysqld restart
# 或者 service mysqld stop service mysqld start 複製代碼
cat /etc/my.cnf
複製代碼
[root@10 /]# cat /etc/my.cnf
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html [mysqld] port=3306 # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove the leading "# " to disable binary logging # Binary logging captures changes between backups and is enabled by # default. It's default setting is log_bin=binlog # disable_log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M # # Remove leading # to revert to previous value for default_authentication_plugin, # this will increase compatibility with older clients. For background, see: # https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin default-authentication-plugin=mysql_native_password datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid 複製代碼
操做步驟
1.在 [mysqld]最後加上以下語句 並保持退出文件;
skip-grant-tables
2.重啓 mysql
service mysqld restart
3.輸入如下命令,點擊enter鍵能夠跳過密碼直接進入mysql
mysql -u root -p
4.查看root用戶的相關信息
select host, user, authentication_string, plugin from user;
能夠看到root用戶中authentication_string就是你以前的密碼的散列值。
5.當前root用戶authentication_string字段下有內容,先將其設置爲空
use mysql;
update user set authentication_string='' where user='root';
6.使用ALTER修改root用戶密碼
ALTER user 'root'@'localhost' IDENTIFIED BY '你的新密碼'
複製代碼
對用戶受權,容許指定用戶遠程訪問,最簡單的方式是將mysql庫中user表中的對應的用戶的host設置爲%,亦即容許該用戶從任意ip遠程訪問
mysql> select user,host from user;
+------------------+-----------+ | user | host | +------------------+-----------+ | root | localhost | | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | +------------------+-----------+ 4 rows in set (0.01 sec) 複製代碼
由上面默認的用戶的host可知,默認只容許本地鏈接,不容許遠程鏈接;
那麼如何遠程鏈接呢?
須要把 host 的 localhost 改成 %;
mysql -u root -p
複製代碼
鏈接成功後:
mysql> use mysql;
mysql> flush privileges;
# localhost 改 %
mysql> update user set host='%' where user='root';
mysql> flush privileges;
複製代碼
而後退出mysql重啓;
最粗暴的方式是直接關閉防火牆
service iptables stop
chkconfig iptables off # 反之開啓防火牆 service iptables start chkconfig iptables on 複製代碼
推薦方式:手動添加防火牆3306
vim /etc/sysconfig/iptables
# 追加如下內容,放行3306端口 -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT # 保存退出以後 #最後重啓防火牆使配置生效 /etc/init.d/iptables restart 複製代碼
以後就能夠遠程登陸了,須要安裝mysql8的同窗趕忙去試試吧。
本文使用 mdnice 排版