目錄
一、官網(wǎng)下載Mysql安裝包
?二、解壓安裝
三、創(chuàng)建mysql用戶組及用戶
四、初始化數(shù)據(jù)庫
五、配置Mysql
六、建立Mysql服務(wù)
七、修改密碼
八、開啟遠(yuǎn)程訪問
九、關(guān)閉Linux防火墻
一、官網(wǎng)下載Mysql安裝包
我的環(huán)境是Centos選擇對應(yīng)系統(tǒng)
MySQL :: Download MySQL Community Server
二、解壓安裝
上傳文件至服務(wù)器,本次演示mysql上傳位置:/appusr/apphome
1.解壓執(zhí)行命令:tar -xvf mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz
2.重命名為:mysql-8.0
mv mysql-8.0.32-linux-glibc2.12-x86_64 mysql-8.0
3.進(jìn)入mysql-8.0的目錄,新建data文件夾
[root@centos-tianmen apphome]# cd mysql-8.0/
[root@centos-tianmen mysql-8.0]# mkdir data
[root@centos-tianmen mysql-8.0]# ll
總用量 296
drwxr-xr-x. 2 7161 31415 4096 12月 17 00:54 bin
drwxr-xr-x. 2 root root 6 3月 19 14:42 data
drwxr-xr-x. 2 7161 31415 56 12月 17 00:54 docs
drwxr-xr-x. 3 7161 31415 4096 12月 17 00:54 include
drwxr-xr-x. 6 7161 31415 201 12月 17 00:54 lib
-rw-r--r--. 1 7161 31415 283374 12月 16 23:34 LICENSE
drwxr-xr-x. 4 7161 31415 30 12月 17 00:54 man
-rw-r--r--. 1 7161 31415 666 12月 16 23:34 README
drwxr-xr-x. 28 7161 31415 4096 12月 17 00:54 share
drwxr-xr-x. 2 7161 31415 77 12月 17 00:54 support-files
4.新增tmp、log目錄后面使用
[root@centos-tianmen mysql-8.0]# mkdir log
[root@centos-tianmen mysql-8.0]# mkdir tmp
三、創(chuàng)建mysql用戶組及用戶
1.新增用戶組mysql
groupadd mysql
2.新增用戶mysql?密碼mysql
useradd -g mysql mysql
3.授權(quán),指向mysql的安裝目錄
chown -R mysql.mysql /appusr/apphome/mysql-8.0/
四、初始化數(shù)據(jù)庫
1.進(jìn)入mysql安裝目錄,我的安裝目錄為:/appusr/apphome/mysql-8.0
[root@centos-tianmen mysql-8.0]# cd /appusr/apphome/mysql-8.0/
[root@centos-tianmen mysql-8.0]# pwd
/appusr/apphome/mysql-8.0
2.初始化數(shù)據(jù)庫
執(zhí)行命令:./bin/mysqld --user=mysql --basedir=/appusr/apphome/mysql-8.0/ --datadir=/appusr/apphome/mysql-8.0/data/ --initialize ;
[root@centos-tianmen mysql-8.0]# ./bin/mysqld --user=mysql --basedir=/appusr/apphome/mysql-8.0/ --datadir=/appusr/apphome/mysql-8.0/data/ --initialize ;
2023-03-19T08:42:40.094583Z 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.
2023-03-19T08:42:40.094889Z 0 [System] [MY-013169] [Server] /appusr/apphome/mysql-8.0/bin/mysqld (mysqld 8.0.32) initializing of server in progress as process 53132
2023-03-19T08:42:40.116956Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-03-19T08:42:40.999879Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-03-19T08:42:43.037019Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: =cFY9lpinfc6
記住臨時(shí)密碼:=cFY9lpinfc6
五、配置Mysql
1.修改配置文件
vi /etc/my.cnf
my.cnf配置文件自用:
#[mysqld]
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
#!includedir /etc/my.cnf.d
[mysql]
#basedir=/appusr/apphome/mysql-8.0
#datadir=/appusr/apphome/mysql-8.0/data/
socket=/appusr/apphome/mysql-8.0/tmp/mysql.sock
port=3306
user=mysql
#skip-grant-tables
# 指定日志時(shí)間為系統(tǒng)時(shí)間
#log_timestamps=SYSTEM
#log-error=/appusr/apphome/mysql-8.0/log/mysql.err
# # 指定字符集為utf8,因?yàn)閙ysql8.0中的默認(rèn)字符集為utfmb4,會(huì)和其他程序引起兼容性問題
default-character-set=utf8
#
#
[mysqld]
basedir=/appusr/apphome/mysql-8.0
datadir=/appusr/apphome/mysql-8.0/data
socket=/appusr/apphome/mysql-8.0/tmp/mysql.sock
port=3306
user=mysql
log_timestamps=SYSTEM
collation-server = utf8_unicode_ci
character-set-server = utf8
# # 指定默認(rèn)認(rèn)證的加密方式,mysql8.0中默認(rèn)方式為caching_sha2_password,引起老版本兼容性問題
default_authentication_plugin= mysql_native_password
#skip-grant-tables
[mysqld_safe]
log-error=/appusr/apphome/mysql-8.0/log/mysqld_safe.err
pid-file=/appusr/apphome/mysql-8.0/tmp/mysqld.pid
socket=/appusr/apphome/mysql-8.0/tmp/mysql.sock
#skip-grant-tables
[mysql.server]
#basedir=/appusr/apphome/mysql-8.0
datadir=/appusr/apphome/mysql-8.0/data
socket=/appusr/apphome/mysql-8.0/tmp/mysql.sock
port=3306
user=mysql
#skip-grant-tables
[mysqladmin]
socket=/appusr/apphome/mysql-8.0/tmp/mysql.sock
六、建立Mysql服務(wù)
1.進(jìn)入mysql安裝目錄
cd /appusr/apphome/mysql-8.0/
2.?添加Mysql到系統(tǒng)服務(wù)
cp -a ./support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
3.檢查服務(wù)是否生效
chkconfig --list mysql
如圖:
[root@centos-tianmen mysql-8.0]# cp -a ./support-files/mysql.server /etc/init.d/mysql
[root@centos-tianmen mysql-8.0]# chmod +x /etc/init.d/mysql
[root@centos-tianmen mysql-8.0]# chkconfig --add mysql
[root@centos-tianmen mysql-8.0]# chkconfig --list mysql
注:該輸出結(jié)果只顯示 SysV 服務(wù),并不包含
原生 systemd 服務(wù)。SysV 配置數(shù)據(jù)
可能被原生 systemd 配置覆蓋。
要列出 systemd 服務(wù),請執(zhí)行 'systemctl list-unit-files'。
查看在具體 target 啟用的服務(wù)請執(zhí)行
'systemctl list-dependencies [target]'。
mysql 0:關(guān) 1:關(guān) 2:開 3:開 4:開 5:開 6:關(guān)
[root@centos-tianmen mysql-8.0]#
4.啟動(dòng)mysql服務(wù)
service mysql start;
如有報(bào)錯(cuò)文件不存在,新建缺失的文件,授權(quán)mysql??
[root@centos-tianmen mysql-8.0]# service mysql start;
Starting MySQL... SUCCESS!
5.查看服務(wù)狀態(tài)
service mysql status;
[root@centos-tianmen mysql-8.0]# service mysql status;
SUCCESS! MySQL running (54691)
七、修改密碼
1.進(jìn)入mysql安裝目錄的bin目錄
cd /appusr/apphome/mysql-8.0/bin/
2.使用上面的臨時(shí)密碼登錄,執(zhí)行命令
./mysql -uroot -p
如圖:?
[root@centos-tianmen 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.32
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
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>
3.修改密碼
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密碼';
OK,到此安裝完成了!
八、開啟遠(yuǎn)程訪問
1.在登錄狀態(tài)執(zhí)行下述SQL
mysql> CREATE USER 'root'@'%' IDENTIFIED BY '密碼';
Query OK, 0 rows affected (0.03 sec)
mysql> GRANT ALL ON *.* TO 'root'@'%';
Query OK, 0 rows affected (0.02 sec)
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密碼';
Query OK, 0 rows affected (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)
九、關(guān)閉Linux防火墻
1.查看防火墻狀態(tài)
systemctl status firewalld.service
[root@centos-tianmen bin]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since 日 2023-03-19 13:39:15 CST; 4h 52min ago
Docs: man:firewalld(1)
Main PID: 704 (firewalld)
Tasks: 2
CGroup: /system.slice/firewalld.service
└─704 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
3月 19 13:39:11 centos-tianmen systemd[1]: Starting firewalld - dynamic firewall daemon...
3月 19 13:39:15 centos-tianmen systemd[1]: Started firewalld - dynamic firewall daemon.
3月 19 13:39:15 centos-tianmen firewalld[704]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release. Please conside...abling it now.
Hint: Some lines were ellipsized, use -l to show in full.
2.目前開啟狀態(tài),關(guān)閉防火墻
systemctl stop firewalld.service
3.再查看防火墻狀態(tài),已經(jīng)關(guān)閉
[root@centos-tianmen bin]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since 日 2023-03-19 18:31:56 CST; 1s ago
Docs: man:firewalld(1)
Process: 704 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
Main PID: 704 (code=exited, status=0/SUCCESS)
3月 19 13:39:11 centos-tianmen systemd[1]: Starting firewalld - dynamic firewall daemon...
3月 19 13:39:15 centos-tianmen systemd[1]: Started firewalld - dynamic firewall daemon.
3月 19 13:39:15 centos-tianmen firewalld[704]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release. Please conside...abling it now.
3月 19 18:31:50 centos-tianmen systemd[1]: Stopping firewalld - dynamic firewall daemon...
3月 19 18:31:56 centos-tianmen systemd[1]: Stopped firewalld - dynamic firewall daemon.
Hint: Some lines were ellipsized, use -l to show in full.
4.設(shè)置永久關(guān)閉防火墻
systemctl disable firewalld.service
[root@centos-tianmen bin]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
5.鏈接Mysql
文章來源:http://www.zghlxwxcb.cn/news/detail-744006.html
?OK,完活文章來源地址http://www.zghlxwxcb.cn/news/detail-744006.html
到了這里,關(guān)于Linux 安裝Mysql8.0的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!