Linux7安裝mysql-8.0.13操作步驟

一、在官網:https://dev.mysql.com/downloads/mysql/下載安裝包通用版的

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

二、前期安裝環境準備

1、清理mysql歷史文件
確保如下幾個目錄沒有mysql有關的文件和目錄:

sudo rm /var/lib/mysql/ -R      # 刪除數據庫目錄
sudo rm /etc/mysql/ -R          #刪除啓動腳本、配置文件等
sudo apt-get autoremove mysql* --purge      # 卸載mysql所有文件
sudo apt-get remove apparmor     # 這個apparmor是在裝mysql-server時裝上的,和安全有關
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P    # 清理殘餘mysql文件

2、上傳解壓壓縮包

把下載的:mysql-8.0.13-linux-glibc2.12-x86_64.tar 上傳到 /usr/local 目錄下。

[root@VM_141_168_centos local]# tar -xzvf mysql-8.0.13-linux-glibc2.12-x86_64.tar

解壓後重命令解壓出來的文件。

[root@VM_141_168_centos local]# mv mysql-8.0.13-linux-glibc2.12-x86_64 mysql

創建data目錄,

mkdir data

三、安裝

創建用戶和用戶組並授權

[root@VM_141_168_centos mysql]# groupadd mysql
[root@VM_141_168_centos mysql]# useradd -r -g mysql -s /bin/false mysql
[root@VM_141_168_centos mysql]# chown mysql:mysql

初始化mysql其中 A temporary password is generated for root@localhost: =8J*BAoEpa1:

root@localhost: 後面的是密碼需要記住很重要

[root@VM_141_168_centos mysql]# /bin/mysql --initialize --user=mysql
2018-12-17T08:29:55.324437Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 27108
2018-12-17T08:30:00.249167Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: =8J*BAoEpa1:
2018-12-17T08:30:03.733389Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.13) initializing of server has completed

將mysql守護線程設置成系統服務,在support-files目錄下提供了默認啓動腳本,通常我們使用默認腳本:mysql.server

[root@VM_141_168_centos mysql]# ls support-files
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@VM_141_168_centos mysql]# cp -a support-files/mysql.server /etc/init.d/mysql.server

配置mysql的環境變量

[root@VM_141_168_centos mysql]# vi /etc/profile
# 打開文件後,在最後一行按 i 即可進入編輯模式
#添加:
export PATH=$PATH:/usr/local/mysql/bin
#添加後按 Esc 鍵輸入 :wq  按 Enter 鍵即可退出。
[root@VM_141_168_centos mysql]# source /etc/profile
#上面這個是使配置文件生效

啓動mysql

[root@VM_141_168_centos mysql]# service mysql.server start

進入sql設置,這個密碼是上面自己初始化的時候的密碼

[root@VM_141_168_centos mysql]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 43
Server version: 8.0.13 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '新密碼';

初始密碼使用一次就過期了需要修改:ALTER USER 'root'@'localhost' IDENTIFIED BY '新密碼';

退出後再次進入就可以使用新密碼了。

四、遠程用戶建立,nvacat連接建立。

create user 用戶名@'%' identified by '密碼';
ALTER USER 用戶名@'%' IDENTIFIED BY '密碼' PASSWORD EXPIRE NEVER; 
ALTER USER 用戶名@'%' IDENTIFIED WITH mysql_native_password BY '密碼'; 
FLUSH PRIVILEGES; 
grant all privileges on *.* to '用戶名'@'%';
FLUSH PRIVILEGES; 

簡歷遠程連接後還要配置防火牆,開通外網訪問端口

#放通端口:
firewall-cmd --permanent --add-port=3306/tcp
#重新啓動就可以了:
systemctl reatart firewalld

五、防火牆相關知識

啓動/查看狀態/停止/禁用/重啓:

systemctl start/status/disable/stop/restart firewalld

查看所有打開的端口: firewall-cmd --zone=public --list-ports

開啓端口:firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,沒有此參數重啓後失效)

重新載入:firewall-cmd --reload

查看:firewall-cmd --zone= public --query-port=80/tcp

刪除:firewall-cmd --zone= public --remove-port=80/tcp --permanent

顯示狀態: firewall-cmd --state

 

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