1.確保系統中有依賴的libaio軟件,使用以下命令mysql
[root@localhost ~]# yum -y install libaio [root@localhost ~]# rpm -q libaio libaio-0.3.109-13.el7.x86_64
2.使用wget命令下載mysql-5.7.24 軟件包linux
[root@localhost ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
3.將mysql安裝包解壓到指定目錄,命令以下:sql
[root@localhost ~]# tar xf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
4.進入/usr/local目錄數據庫
[root@localhost ~]# cd /usr/local/
5.爲mysql安裝目錄建立軟連接vim
[root@localhost local]# ln -s mysql-5.7.24-linux-glibc2.12-x86_64/ mysql
6.添加mysql用戶和組和bash
[root@localhost local]# useradd -M -s /sbin/nologin mysql
7.修改當前目錄擁有者爲新建的mysql用戶,命令以下:socket
[root@localhost mysql]# chown -R mysql:mysql ./
8.初始化mysql數據庫(創建默認的庫和表),命令以下:tcp
[root@localhost mysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
將隨機生成的登陸密碼記錄下來: e9iIEYBa9t!fide
9.開啓mysqld服務,命令以下spa
[root@localhost mysql]# vim /etc/my.cnf [mysqld] datadir=/usr/local/mysql/data socket=/tmp/mysql.sock [mysqld_safe] log-error=/usr/local/mysql/data/mysql.log pid-file=/usr/local/mysql/data/mysql.pid [root@localhost mysql]# ./support-files/mysql.server start Starting MySQL.Logging to '/usr/local/mysql/data/mariadb.log'. . SUCCESS! [root@localhost mysql]# netstat -lnpt |grep :3306 tcp6 0 0 :::3306 :::* LISTEN 2220/mysqld
10.將mysqd服務添加到系統服務中,命令以下
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@localhost mysql]# ls -l /etc/init.d/mysqld -rwxr-xr-x 1 root root 10576 12月 7 16:12 /etc/init.d/mysqld [root@localhost mysql]# service mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL.. SUCCESS!
11.使用隨機密碼登陸mysql數據庫,命令以下
[root@localhost mysql]# ./bin/mysql -u root -p
等待系統提示,輸入隨機密碼,便可登陸
12.設置mysql管理用戶root的新密碼
[root@localhost mysql]# ./bin/mysqladmin -u root -p'e9iIEYBa9t!f' password '123456'
13.將mysql命令添加到系統命令執行路徑中,便於使用。
[root@localhost mysql]# ln -s /usr/local/mysql/bin/* /usr/local/bin/ [root@localhost mysql]# cd [root@localhost ~]# mysql -u root -p123456