安裝mysql5.7

1.下載mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz的安裝包mysql

tar -xvf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz

2.解壓mysql-8.0.13-linux-glibc2.12-x86_64.tar.xzlinux

# tar -xvf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz

3.將解壓的文件重命名mysql,並移動到/usr/local目錄下sql

# mv mysql-8.0.13-linux-glibc2.12-x86_64 mysql
# mv mysql /usr/local/

4.進入到/usr/local目錄下,建立用戶和用戶組並受權數據庫

# cd /usr/local/
# groupadd mysql
# useradd -r -g mysql mysql
# cd mysql/ #注意:進入mysql文件下受權全部的文件
# chown -R mysql:mysql ./

5.再/usr/local/mysql目錄下,建立data文件夾vim

# mkdir data

6.初始化數據庫,並會自動生成隨機密碼,記下等下登錄要用socket

# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

7.修改/usr/local/mysql當前目錄得用戶ui

若是出現 `error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory`。解決問題具體操做以下。

yum -y install numactl
yum -y install libaiorest

# chown -R root:root ./
# chown -R mysql:mysql data

8.複製文件my.cnf,開始是沒有my-default.cnf這個文件,須要手動建立。能夠用# touch my-default.cnf命令建立一個,並配置權限。日誌

# cp support-files/my-default.cnf /etc/my.cnf 
# chmod 777 ./my-default.cnf 

# cd support-files/
# touch my-default.cnf
# chmod 777 ./my-default.cnf 
# cd ../
# cp support-files/my-default.cnf /etc/my.cnf

配置my.cnfcode

# 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 = 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

若是後期mysql運行報錯,能夠直接到log-error = /usr/local/mysql/data/error.log目錄下直接查看錯誤日誌

命令:cat /usr/local/mysql/data/error.log

10.開機自啓,進入/usr/local/mysql/support-files進行設置

# cd support-files/
# cp mysql.server /etc/init.d/mysql 
# chmod +x /etc/init.d/mysql

11.註冊服務

# chkconfig --add mysql

12.etc/ld.so.conf要配置路徑,否則報錯

# vim /etc/ld.so.conf
 
添加以下內容:
/usr/local/mysql/lib
:q

13.配置環境變量

# vim /etc/profile
# source /etc/profile
 
添加以下內容:
#MYSQL ENVIRONMENT
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib

若是每次退出容器,須要source /etc/profile

  1. 啓動服務
# cp -a ./support-files/mysql.server /etc/init.d/mysqld
# cd bin/
# ./mysqld_safe --user=mysql &
# /etc/init.d/mysqld restart

15.登錄,這裏輸入上面第6步隨機生成得密碼,細心點輸入,沒有顯示的,登錄成功如圖所示

# mysql -uroot -p
... 
密碼
...

若是失敗,出現/tmp/mysql.sock。 首先刪除/tmp/mysql.sock,而後給目錄受權 chown -R mysql.mysql /tmp/*

# rm -rf /tmp/mysql.sock
# chown -R mysql.mysql /tmp/*

若是出現,沒法登錄的狀況修改my.cnf文件。[mysqld]後面任意一行添加「skip-grant-tables」用來跳過密碼驗證的過程。

# vim /etc/my.cnf
...
...

重啓服務

# /etc/init.d/mysqld restart

從新設置密碼

# mysql
mysql> use mysql;
mysql> update user set password=password("你的新密碼") where user="root";

mysql> flush privileges;
mysql> quit
相關文章
相關標籤/搜索