Linux上安裝mysql8.0.19

1.下載mysql

選擇下載Linux - Generic (glibc 2.12) (x86, 64-bit), TAR

在這裏插入圖片描述

2.上傳到服務器後進行解壓並安裝

2.1 解壓壓縮包

$ tar -xvf mysql-8.0.19-linux-glibc2.12-x86_64.tar 
mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
mysql-test-8.0.19-linux-glibc2.12-x86_64.tar.xz
mysql-router-8.0.19-linux-glibc2.12-x86_64.tar.xz

2.2 解壓後得到xz後綴壓縮包,解壓mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz

$ tar -xvf mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz 
mysql-8.0.19-linux-glibc2.12-x86_64/bin/
mysql-8.0.19-linux-glibc2.12-x86_64/bin/myisam_ftdump
mysql-8.0.19-linux-glibc2.12-x86_64/bin/myisamchk
mysql-8.0.19-linux-glibc2.12-x86_64/bin/myisamlog
mysql-8.0.19-linux-glibc2.12-x86_64/bin/myisampack
mysql-8.0.19-linux-glibc2.12-x86_64/bin/mysql
mysql-8.0.19-linux-glibc2.12-x86_64/bin/mysql_config_editor
mysql-8.0.19-linux-glibc2.12-x86_64/bin/mysql_secure_installation
mysql-8.0.19-linux-glibc2.12-x86_64/bin/mysql_ssl_rsa_setup
mysql-8.0.19-linux-glibc2.12-x86_64/bin/mysql_tzinfo_to_sql
mysql-8.0.19-linux-glibc2.12-x86_64/bin/mysql_upgrade
mysql-8.0.19-linux-glibc2.12-x86_64/bin/mysqladmin
mysql-8.0.19-linux-glibc2.12-x86_64/bin/mysqlbinlog
......

#解壓後,重命名爲mysql-8.0.19,並移動到/usr/local目錄下
$ mv mysql-8.0.19-linux-glibc2.12-x86_64/ /usr/local/mysql

2.3 添加用戶名和用戶組

$ cd /usr/local/mysql
$ groupadd mysql
$ useradd -r -g mysql mysql
$ chown -R mysql:mysql ./

在/usr/local/mysql下創建data文件夾

$ mkdir data

2.4 初始化數據庫,會自動生成密碼 記得記下來,後面登錄修改密碼要用到

$ cd /usr/local/mysql/bin
$ ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2020-03-26T08:06:37.751865Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-03-26T08:06:37.752022Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.19) initializing of server in progress as process 13594
2020-03-26T08:06:42.182558Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: tD&LZNEsm3Et

在初始化的過程中,可能會出現*./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory*這個錯誤,原因是缺少了libaio,這裏執行安裝yum -y install numactl後,重新初始化就可以了

2.5 創建配置文件及相關目錄(如果在這個路徑下已經存在的話就不用創建了)

創建配置文件:vim /etc/my.cnf

文件模板:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It‘s a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[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 = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....

# 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

修改配置文件內容:注意要在模板的 [mysqld] 下面去修改(basedir:mysql安裝路徑,datadir:數據存儲目錄)

[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 = /var/log/mysqld.log
character-set-server = utf8
pid-file = /tmp/mysqld/mysqld.pid
tmpdir = /tmp
port = 3306
#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

保存退出:wq!

創建文件/tmp/mysql.sock:設置用戶組及用戶,授權

cd /tmp
touch mysql.sock
chown mysql:mysql mysql.sock
chmod 755 mysql.sock

創建文件/tmp/mysqld/mysqld.pid

mkdir mysqld
cd mysqld
touch mysqld.pid
cd ..
chown -R mysql:mysql mysqld
cd mysqld
chmod 755 mysqld.pid

創建文件/var/log/mysqld.log:

touch /var/log/mysqld.log
chown -R mysql:mysql /var/log
cd /var/log
chmod 755 mysqld.log

2.6 安裝和初始化數據庫

進入初始化目錄:cd /usr/local/mysql/bin/

初始化數據庫:./mysqld --initialize --user=mysql --basedir=/usr/local/mysql–datadir=/usr/local/mysql/data

如果報錯:(./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory)

需要安裝命令:yum -y install numactl

之後在執行初始化數據庫:./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

2.7 啓動數據庫

./mysqld_safe --user=mysql &

查看是否成功:ps -ef | grep mysql

默認密碼在mysqld.log日誌裏, cat /var/log/mysqld.log,其中root@localhost: 後面的就是默認密碼

$ /usr/local/mysql/bin/mysql -u root -p  #回車後輸入密碼

# 創建新用戶
mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'Hadoop3!';

# 修改用戶密碼
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '111';
# 給user用戶添加權限
mysql> grant all privileges on *.* to 'root'@'%';

# 刷新登錄權限
mysql> flush privileges;

2.8 配置mysql允許遠程連接的方法

默認情況下,mysql只允許本地登錄,如果要開啓遠程連接,則需要修改/etc/my.cnf文件。還要改登錄用戶添加權限
找到bind-address = 127.0.0.1這一行
改爲bind-address = 0.0.0.0即可

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章