下載官方打包好的rpm的集合html
https://downloads.mysql.com/archives/get/file/mysql-5.7.20-1.el7.x86_64.rpm-bundle.tarnode
[root@xuegod63 opt]# tar xf mysql-5.7.20-1.el7.x86_64.rpm-bundle.tarmysql
解壓出來,發現有不少rpm包,咱們須要用到的包是:linux
mysql-community-common-5.7.20-1.el7.x86_64.rpmsql
mysql-community-libs-5.7.20-1.el7.x86_64.rpmshell
mysql-community-client-5.7.20-1.el7.x86_64.rpm數據庫
mysql-community-server-5.7.20-1.el7.x86_64.rpm安全
依次安裝:app
yum install mysql-community-common-5.7.20-1.el7.x86_64.rpm -yui
yum install mysql-community-libs-5.7.20-1.el7.x86_64.rpm -y
yum install mysql-community-client-5.7.20-1.el7.x86_64.rpm -y
yum install mysql-community-server-5.7.20-1.el7.x86_64.rpm -y
注意安裝 mysql-community-server-5.7.20-1.el7.x86_64.rpm報錯
[root@b mysql-5.7.26]# yum install mysql-community-server-5.7.26-1.el6.x86_64.rp m -y
Error: Package: mysql-community-server-5.7.26-1.el6.x86_64 (/mysql-community-ser ver-5.7.26-1.el6.x86_64)
Requires: libsasl2.so.2()(64bit)
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
[root@b mysql-5.7.26]# rpm -ivh mysql-community-server-5.7.26-1.el6.x86_64.rpm
warning: mysql-community-server-5.7.26-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libsasl2.so.2()(64bit) is needed by mysql-community-server-5.7.26-1.el6.x86_64
緣由:這是因爲yum安裝了舊版本的GPG keys形成的 解決辦法: --force --nodeps
[root@b mysql-5.7.26]# rpm -ivh mysql-community-server-5.7.26-1.el6.x86_64.rpm --force --nodeps
warning: mysql-community-server-5.7.26-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-5.7.26-1.e################################# [100%]
(注意:安裝順序不能錯,不然會報錯依賴包沒有安裝)
查看安裝路徑:
[root@xuegod63 opt]# rpm -ql mysql-community-server
能夠看到數據庫安裝在/var/lib/mysql 目錄下
啓動服務:
[root@xuegod63 opt]# systemctl start mysqld.service
獲取臨時密碼:
第一次經過# grep "password" /var/log/mysqld.log 命令獲取MySQL的臨時密碼
用該密碼登陸到服務端後,必須立刻修改密碼,否則操做查詢時報錯誤
[root@xuegod63 opt]# grep "password" /var/log/mysqld.log
2017-11-10T14:38:40.930543Z 1 [Note] A temporary password is generated for root@localhost: itBp#lFva0aY
補充注意:MySQL5.7以前的版權,初次安裝MySQL,默認登錄密碼是空,5.7以後的版本,默認登錄的密碼爲一個隨機生產的字符串,存在/var/log/mysqld.log 文件裏。
安全初始化操做:
[root@xuegod65 opt]# mysql_secure_installation
修改默認密碼和相關的權限
MySQL5.7對密碼複雜度要求比較高,剛開始設置的密碼必須符合長度(默認最小長度的8),且必須含有數字,小寫或大寫字母,特殊字符。
這也是從安全考慮,但願使用者不要強行修改密碼策略,設置簡單的密碼
Welcome1qazx@com
若是想設置簡單密碼,以下操做:
[root@localhost ~]# mysql -uroot -p' itBp#lFva0aY '
方法一:首先,修改validate_password_policy參數的值
mysql> set global validate_password_policy=0; #定義複雜度
mysql> set global validate_password_length=1; #定義長度 默認是8
方法二:在/etc/my.cnf 可關閉密碼強度審計插件,重啓mysql服務
validate_password=ON/OFF/FORCE/FORCE_PLUS_PERMANENT: 決定是否使用該插件(及強制/永久強制使用)。
修改密碼
mysql>
set password for 'root'@'localhost'=password('123456'); 修改root帳號登錄密碼
Query OK, 0 rows affected, 1 warning (0.05 sec)
刷新權限表(使更改密碼當即生效而不用重啓mysql)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
登錄linux下的mysql5.7忘記密碼
解決方法
[root@iz09a32x1sghz3z ~]# vi /etc/my.cnf
[root@iz09a32x1sghz3z ~]# service mysqld restart
用root帳號登陸: [root@iz09a32x1sghz3z ~]# mysql -u root
使用mysql中的mysql數據庫: mysql> use mysql;
修改密碼: update user set authentication_string = password("Szfore_68638") where user="root" ;
刷新數據庫: flush privileges;
退出: quit;
注意:mysql5.7的user表中的password字段已經改爲了authentication_string 字段了。
這時候,須要輸入的命令是update user set authentication_string = password("Szfore_68638") where user="root" ;
Table 2.11 MySQL Installation Layout for Linux RPM Packages from the MySQL Developer Zone
Files or Resources | Location |
---|---|
Client programs and scripts | /usr/bin |
mysqld server | /usr/sbin |
Configuration file | /etc/my.cnf |
Data directory | /var/lib/mysql |
Error log file | For RHEL, Oracle Linux, CentOS or Fedora platforms: For SLES: |
Value of secure_file_priv |
/var/lib/mysql-files |
System V init script | For RHEL, Oracle Linux, CentOS or Fedora platforms: For SLES: |
Systemd service | For RHEL, Oracle Linux, CentOS or Fedora platforms: For SLES: |
Pid file | /var/run/mysql/mysqld.pid |
Socket | /var/lib/mysql/mysql.sock |
Keyring directory | /var/lib/mysql-keyring |
Unix manual pages | /usr/share/man |
Include (header) files | /usr/include/mysql |
Libraries | /usr/lib/mysql |
Miscellaneous support files (for example, error messages, and character set files) | /usr/share/mysql |
RHEL, Oracle Linux, CentOS, and Fedora systems:
shell> sudo grep 'temporary password' /var/log/mysqld.log
The next step is to log in with the generated, temporary password and set a custom password for the superuser account:
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';