基於通用二進位制方式安裝MySQL-5.7.24
阿新 • • 發佈:2018-12-08
1.確保系統中有依賴的libaio軟體,使用如下命令
[[email protected] ~]# yum -y install libaio [[email protected] ~]# rpm -q libaio libaio-0.3.109-13.el7.x86_64
2.使用wget命令下載mysql-5.7.24 軟體包
[[email protected] ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
3.將mysql安裝包解壓到指定目錄,命令如下:
[[email protected] ~]# tar xf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
4.進入/usr/local目錄
[[email protected] ~]# cd /usr/local/
5.為mysql安裝目錄建立軟連結
[[email protected] local]# ln -s mysql-5.7.24-linux-glibc2.12-x86_64/ mysql
6.新增mysql使用者和組和
[[email protected] local]# useradd -M -s /sbin/nologin mysql
7.修改當前目錄擁有者為新建的mysql使用者,命令如下:
[[email protected] mysql]# chown -R mysql:mysql ./
8.初始化mysql資料庫(建立預設的庫和表),命令如下:
[[email protected] mysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
將隨機生成的登入密碼記錄下來: e9iIEYBa9t!f
9.開啟mysqld服務,命令如下
[[email protected] 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 [[email protected] mysql]# ./support-files/mysql.server start Starting MySQL.Logging to '/usr/local/mysql/data/mariadb.log'. . SUCCESS! [[email protected] mysql]# netstat -lnpt |grep :3306 tcp6 0 0 :::3306 :::* LISTEN 2220/mysqld
10.將mysqd服務新增到系統服務中,命令如下
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld [[email protected] mysql]# ls -l /etc/init.d/mysqld -rwxr-xr-x 1 root root 10576 12月 7 16:12 /etc/init.d/mysqld [[email protected] mysql]# service mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL.. SUCCESS!
11.使用隨機密碼登入mysql資料庫,命令如下
[[email protected] mysql]# ./bin/mysql -u root -p
等待系統提示,輸入隨機密碼,即可登入
12.設定mysql管理使用者root的新密碼
[[email protected] mysql]# ./bin/mysqladmin -u root -p'e9iIEYBa9t!f' password '123456'
13.將mysql命令新增到系統命令執行路徑中,便於使用。
[[email protected] mysql]# ln -s /usr/local/mysql/bin/* /usr/local/bin/ [[email protected] mysql]# cd [[email protected] ~]# mysql -u root -p123456