1. 程式人生 > >Linux 系統 :CentOS7.X版本下安裝MySQL5.7資料庫

Linux 系統 :CentOS7.X版本下安裝MySQL5.7資料庫

設定rpm下載目錄在/opt目錄下新建一個目錄存放mysql

cd /opt sudo mkdir mysql12

下載MySQL的源

如果在這之前沒有提示-bash: wget: command not found,那麼還得先安裝wget

sudo yum install wget1

安裝MySQL的rpm

sudo rpm -ivh mysql57-community-release-el7-8.noarch.rpm1

安裝MySQL

sudo yum install mysql-server1

在這步中只需要一直y然後回車就行,資料庫就安裝好了,現在進行連線:

mysql -uroot -p root ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)123

這是/var/lib/mysql許可權問題,修改MySQL許可權為當前使用者

sudo chown -R xxx:xxx /var/lib/mysql1

xxx為當前的使用者名稱以及所屬組  重啟MySQL服務

service mysqld restart1

密碼輸入root即可  如果還不行的話通過這個命令獲得初始密碼

cat /var/log/mysqld.log | grep password1

其中A temporary password is generated for [email protected]: bGlY?13TtFyX–:後面的就是初始密碼;登陸進去之後先不做其他操作,作如下操作:

set global validate_password_policy=0; set global validate_password_length=4;12

設定密碼

alter user ‘root’@‘localhost’ identified by ‘root’;1

自此CentOS安裝MySQL5.7就完美安裝了

mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.20 MySQL Community Server (GPL)

Copyright © 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql>