天天看點

MySQL8.0安裝與配置

一、下載下傳MySQL

進入官網:https://downloads.mysql.com/archives/community/選擇合适的版本:

MySQL8.0安裝與配置

通過wget進行下載下傳:

[root@iZwz9ba9y5k8ij7xf2boohZ software]# wget https://downloads.mysql.com/archives/get/p/23/file/  \
mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz      

二、安裝與配置

1、建立mysql使用者群組

# 建立MySQL使用者
[root@iZwz9ba9y5k8ij7xf2boohZ software]#useradd mysql -s /sbin/nologin -M -g mysql

# 建立MySQL組
[root@iZwz9ba9y5k8ij7xf2boohZ software]#groupadd mysql      

2、解壓

[root@iZwz9ba9y5k8ij7xf2boohZ software]# tar-xf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz       

3、安裝

# 1、重命名
[root@iZwz9ba9y5k8ij7xf2boohZ software]# mv mysql-8.0.13-linux-glibc2.12-x86_64 mysql

# 2、拷貝到/usr/local下
[root@iZwz9ba9y5k8ij7xf2boohZ software]# mv mysql /usr/local/

#3、 進入到/usr/local/mysql目錄下,進行授權
[root@iZwz9ba9y5k8ij7xf2boohZ mysql]# chown -R mysql:mysql ./

# 4、初始化
[root@iZwz9ba9y5k8ij7xf2boohZ mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data      

注意:

  • 不需要提前建立好data目錄,否則會出現[ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting問題
  • 會生成臨時密碼,記得儲存

4、配置

  • my.cnf

進入到/usr/local/mysql/support-files目錄中:

# 1、建立my-default.cnf檔案
[root@iZwz9ba9y5k8ij7xf2boohZ support-files]# touch my-default.cnf

# 2、賦予檔案權限
[root@iZwz9ba9y5k8ij7xf2boohZ support-files]# chmod 777 my-default.cnf 

# 3、将其覆寫/etc/my.cnf
[root@iZwz9ba9y5k8ij7xf2boohZ support-files]# cp my-default.cnf /etc/my.cnf 

# 4、寫入對應配置
[root@iZwz9ba9y5k8ij7xf2boohZ support-files]# vim /etc/my.cnf       

vim /etc/my.cnf

[mysqld]
 
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
 
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
 
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
log-error = /usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mysql.pid
tmpdir = /tmp
port = 5186
#lower_case_table_names = 1
# server_id = .....
# socket = .....
#lower_case_table_names = 1
max_allowed_packet=32M
default-authentication-plugin = mysql_native_password
#lower_case_file_system = on
#lower_case_table_names = 1
log_bin_trust_function_creators = ON
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 
 
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES      
  • 啟動配置
# 啟動檔案拷貝
[root@iZwz9ba9y5k8ij7xf2boohZ support-files]# cp mysql.server /etc/init.d/mysql
# 服務可執行權限
[root@iZwz9ba9y5k8ij7xf2boohZ support-files]# chmod +x /etc/init.d/mysql      

5、啟動MySQL

# 啟動MySQL
[root@iZwz9ba9y5k8ij7xf2boohZ support-files]# /etc/init.d/mysql start
Starting MySQL.Logging to '/usr/local/mysql/data/error.log'.
.                                                          [  OK  ]

# 檢視
[root@iZwz9ba9y5k8ij7xf2boohZ ~]# netstat -tunlp|grep 5186
tcp6       0      0 :::5186                 :::*                    LISTEN      7249/mysqld               

6、用戶端環境變量配置

[root@iZwz9ba9y5k8ij7xf2boohZ bin]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile
[root@iZwz9ba9y5k8ij7xf2boohZ bin]# source /etc/profile      

7、修改密碼

 首先使用臨時生成的密碼進行登入,然後修改密碼:

# 登入
[root@iZwz9ba9y5k8ij7xf2boohZ bin]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.13

# 修改密碼
mysql> alter user 'root'@'localhost' identified by '********';
Query OK, 0 rows affected (0.08 sec)      

此時,可以退出,再使用新密碼進行登入了。

8、遠端登入

mysql> select host,user from mysql.user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
4 rows in set (0.00 sec)

mysql> update mysql.user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)      

參考:https://blog.csdn.net/atongmu2017/article/details/90610444 

作者:iveBoy

出處:http://www.cnblogs.com/shenjianping/

本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須在文章頁面給出原文連接配接,否則保留追究法律責任的權利。