本文操作系統: CentOS 7.2.1511 x86_64MySQL 版本: 5.7.13 1、卸載系統自帶的 mariadb-lib 2、下載 rpm 安裝包 去官網找到最新的 rpm 集合包。現在最新的是 mysql-5.7.13-1.el7.x86_64.rpm-bundle.tar 複製其 ...
本文操作系統: CentOS 7.2.1511 x86_64
MySQL 版本: 5.7.13
1、卸載系統自帶的 mariadb-lib
[root@centos-linux ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@centos-linux ~]# rpm -e mariadb-libs-5.5.44-2.el7.centos.x86_64 --nodeps
2、下載 rpm 安裝包
去官網找到最新的 rpm 集合包。現在最新的是 mysql-5.7.13-1.el7.x86_64.rpm-bundle.tar
複製其下載地址,在伺服器下載 (或者本地下載了上傳至伺服器)。
[root@centos-linux ~]# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.13-1.el7.x86_64.rpm-bundle.tar
然後解壓
[root@centos-linux ~]# ls
mysql-5.7.13-1.el7.x86_64.rpm-bundle.tar
[root@centos-linux ~]# tar xvf mysql-5.7.13-1.el7.x86_64.rpm-bundle.tar
mysql-community-test-5.7.13-1.el7.x86_64.rpm
mysql-community-embedded-5.7.13-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.13-1.el7.x86_64.rpm
mysql-community-server-5.7.13-1.el7.x86_64.rpm
mysql-community-client-5.7.13-1.el7.x86_64.rpm
mysql-community-common-5.7.13-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.13-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.13-1.el7.x86_64.rpm
mysql-community-devel-5.7.13-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.13-1.el7.x86_64.rpm
mysql-community-libs-5.7.13-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.13-1.el7.x86_64.rpm
3、安裝
依次執行(幾個包有依賴關係,所以執行有先後)下麵命令安裝
[root@centos-linux ~]# rpm -ivh mysql-community-common-5.7.13-1.el7.x86_64.rpm
[root@centos-linux ~]# rpm -ivh mysql-community-libs-5.7.13-1.el7.x86_64.rpm
[root@centos-linux ~]# rpm -ivh mysql-community-client-5.7.13-1.el7.x86_64.rpm
[root@centos-linux ~]# rpm -ivh mysql-community-server-5.7.13-1.el7.x86_64.rpm
4、資料庫初始化
在 *nix 系統中,為了保證資料庫目錄為與文件的所有者為 mysql 登陸用戶,如果你是以 root 身份運行 mysql 服務,需要執行下麵的命令初始化
mysqld --initialize --user=mysql
如果是以 mysql 身份運行,則可以去掉 --user
選項。
另外 --initialize
選項預設以“安全”模式來初始化,則會為 root 用戶生成一個密碼並將該密碼標記為過期,登陸後你需要設置一個新的密碼,而使用 --initialize-insecure
命令則不使用安全模式,則不會為 root 用戶生成一個密碼。
這裡演示使用的 --initialize
初始化的,會生成一個 root 賬戶密碼,密碼在log文件里
[root@centos-linux ~]# cat /var/log/mysqld.log
2016-07-16T07:56:38.282824Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-07-16T07:56:38.422114Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-07-16T07:56:38.449315Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-07-16T07:56:38.457910Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: d3261dbf-4b2a-11e6-86ef-001c4260563f.
2016-07-16T07:56:38.458976Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-07-16T07:56:38.459524Z 1 [Note] A temporary password is generated for root@localhost: hm9dKgzQdm:W
上圖裡的最後一行則給出了生成的密碼,現在就可以啟動資料庫了,然後使用上面的密碼登陸。
[root@centos-linux ~]# systemctl start mysqld
[root@centos-linux ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.13
Copyright (c) 2000, 2016, 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>
5、修改 root 密碼
該密碼被標記為過期了,如果想正常使用還需要修改密碼
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
以前的 password()
函數將會被拋棄,官方建議使用下麵的命令來修改密碼
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
同時,如果你設置的密碼過於簡單也會報錯。
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
溫馨提示:密碼要複雜,安全是第一呦!!