CentOS 7.3下安裝MySQL 5.7
阿新 • • 發佈:2019-02-17
1、 下載
選擇你需要安裝的版本,這裡我的電腦是CentOS7.3 64位
然後下載 RPM Bundle,這個是幾個程式的合集包。
然後開始下載。。。。
2、 解壓安裝包
解壓mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
#tar -xvf mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-5.7.20-1.el7.x86_64.rpm
mysql-community-common-5.7.20-1.el7.x86_64.rpm
mysql-community -devel-5.7.20-1.el7.x86_64.rpm
mysql-community-embedded-5.7.20-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.20-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.20-1.el7.x86_64.rpm
mysql-community-libs-5.7.20-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm
mysql-community-minimal -debuginfo-5.7.20-1.el7.x86_64.rpm
mysql-community-server-5.7.20-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.20-1.el7.x86_64.rpm
mysql-community-test-5.7.20-1.el7.x86_64.rpm
#ls
-rw-r--r-- 1 7155 31415 25090196 Sep 14 23:44 mysql-community-client-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 278300 Sep 14 23:44 mysql-community-common-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 3778120 Sep 14 23:44 mysql-community-devel-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 46238924 Sep 14 23:44 mysql-community-embedded-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 24077232 Sep 14 23:44 mysql-community-embedded-compat-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 128440800 Sep 14 23:44 mysql-community-embedded-devel-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 2238604 Sep 14 23:44 mysql-community-libs-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 2115892 Sep 14 23:44 mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 55538708 Sep 14 23:44 mysql-community-minimal-debuginfo-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 171597916 Sep 14 23:45 mysql-community-server-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 15256460 Sep 14 23:45 mysql-community-server-minimal-5.7.20-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 118609776 Sep 14 23:45 mysql-community-test-5.7.20-1.el7.x86_64.rpm
3、安裝
解除安裝已安裝的mysql-libs
# rpm -qa | grep -i mysql
mysql-libs-5.1.73-8.el6_8.x86_64
#yum remove mysql-libs
安裝
rpm -ivh mysql-community-common-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.20-1.el7.x86_64.rpm
MySQL 的配置檔案位於:/etc/my.cnf ,根據需求修改配置
預設的datadir=/var/lib/mysql
啟動mysql
# systemctl start mysqld
4、初始化
這種方式安裝好後,會在mysqld.log檔案中自動生成一個密碼,執行看一下吧:
# cat /var/log/mysqld.log | grep password
2017-05-13T05:39:44.497086Z 1 [Note] A temporary password is generated for root@localhost: pKsO:Jin<4f%
密碼就是這麼複雜,複製吧,不然手輸還容易出錯。
登陸:
#mysql -u root -p
Enter password:pKsO:Jin<4f%
mysql>
輸入初始密碼後,就可以登入了;
登入後需要重置密碼,如果不重置,則不讓操作
mysql> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
這裡可以直接使用命令修改root使用者密碼
SET PASSWORD = PASSWORD('passwd');
5、建立使用者
登入
# mysql -u root -p
Enter password:
mysql>
建立資料庫,指定編碼utf-8:
mysql> CREATE DATABASE db182915 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
新增使用者 test:
mysql> GRANT ALL PRIVILEGES ON db182915.* TO 'test'@'192.168.%' IDENTIFIED BY 'test123#' WITH GRANT OPTION;
mysql> flush privileges;