linux安裝mysql8.0
MySQL 8 正式版 8.0.11 已釋出,官方表示 MySQL 8 要比 MySQL 5.7 快 2 倍,還帶來了大量的改進和更快的效能!
以下為本人2018.4.23日安裝過程的記錄。整個過程大概需要一個小時,make && make install過程需要的時間較長。
一.環境
CentOS7.4 64位 最小化安裝
二.準備工作
1.安裝依賴
yum -y install wget cmake gcc gcc-c++ ncurses ncurses-devel libaio-devel openssl openssl-devel
2.下載原始碼包
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.11.tar.gz (此版本帶有boost)
3.建立mysql使用者
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
4.建立安裝目錄和資料目錄
mkdir -p /usr/local/mysql
mkdir -p /data/mysql
三.安裝MySQL8.0.11
1.解壓原始碼包
tar -zxf mysql-boost-8.0.11.tar.gz -C /usr/local
2.編譯&安裝
cd /usr/local/mysql-8.0.11
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=/usr/local/mysql-8.0.11/boost
make && make install
3.配置my.cnf檔案
cat /etc/my.cnf
[mysqld]
server-id=1
port=3306
basedir=/usr/local/mysql
datadir=/data/mysql
##請根據實際情況新增引數
4.目錄許可權修改
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /data/mysql
chmod 755 /usr/local/mysql -R
chmod 755 /data/mysql -R
5.初始化
bin/mysqld --initialize --user=mysql --datadir=/data/mysql/
bin/mysql_ssl_rsa_setup
6.啟動mysql
bin/mysqld_safe --user=mysql &
7.修改賬號密碼
bin/mysql -uroot -p
mysql> alter user 'root'@'localhost' identified by "123456";
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
##新增遠端特賬號
mysql> create user root@'%' identified by '123456';
Query OK, 0 rows affected (0.08 sec)
mysql> grant all privileges on *.* to root@'%';
Query OK, 0 rows affected (0.04 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
8.建立軟連結(非必要)
ln -s /usr/local/mysql/bin/* /usr/local/bin/
mysql -h 127.0.0.1 -P 3306 -uroot -p123456 -e "select version();"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-----------+
| version() |
+-----------+
| 8.0.11 |
+-----------+
9.新增到啟動(非必要)
cp support-files/mysql.server /etc/init.d/mysql.server
10.yum install -y mariadb-server //安裝mariadb-server
11. systemctl start mariadb.service //啟動mysql
12.systemctl enable mariadb.service //新增開機啟動項
13.mysql -u root -p //進入mysql