当前位置:   article > 正文

Centos7安装Mysql8_centos7安装mysql8.0tar

centos7安装mysql8.0tar

Centos7安装Mysql8

1.卸载Centos原生自带的mariadb

mariadb和mysql同是开源数据库软件,要求不高,一定程度上可以替代使用,本次安装卸载掉以免影响
mysql安装包链接: https://pan.baidu.com/s/1Le9bWzqqo_RB_2bWjgNVdQ 提取码: b4ql
如果失效,私信获取

[root@localhost ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost ~]# rpm -qa|grep mariad
  • 1
  • 2
  • 3
  • 4

2.解压mysql

[root@localhost ~]# tar -xf mysql-8.0.33-el7-x86_64.tar 
[root@localhost ~]# ll
total 1893720
-rw-------. 1 root root       1276 May 25 16:23 anaconda-ks.cfg
-rwx------. 1 root root  969577984 May 25 16:50 mysql-8.0.33-el7-x86_64.tar
-rw-r--r--. 1 7161 31415 526786640 Mar 17 02:38 mysql-8.0.33-el7-x86_64.tar.gz
-rw-r--r--. 1 7161 31415  26158261 Mar 17 02:35 mysql-router-8.0.33-el7-x86_64.tar.gz
-rw-r--r--. 1 7161 31415 416629354 Mar 17 02:37 mysql-test-8.0.33-el7-x86_64.tar.gz
[root@localhost ~]# tar -xf mysql-8.0.33-el7-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ll
total 0
drwxr-xr-x. 2 root root   6 Apr 11  2018 bin
drwxr-xr-x. 2 root root   6 Apr 11  2018 etc
drwxr-xr-x. 2 root root   6 Apr 11  2018 games
drwxr-xr-x. 2 root root   6 Apr 11  2018 include
drwxr-xr-x. 2 root root   6 Apr 11  2018 lib
drwxr-xr-x. 2 root root   6 Apr 11  2018 lib64
drwxr-xr-x. 2 root root   6 Apr 11  2018 libexec
drwxr-xr-x. 9 root root 129 May 25 16:53 mysql-8.0.33-el7-x86_64
drwxr-xr-x. 2 root root   6 Apr 11  2018 sbin
drwxr-xr-x. 5 root root  49 May 25 16:17 share
drwxr-xr-x. 2 root root   6 Apr 11  2018 src
[root@localhost local]# mv mysql-8.0.33-el7-x86_64 mysql
[root@localhost local]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

3.建立用户并授权

这里使用系统非root账户管理mysql

这里将数据放在了/usr/local/mysql/data/下,如果需要更改修改初始化时的–datadir=参数和/etc/my.cnf的datadir和socket

[root@localhost local]# pwd
/usr/local
[root@localhost local]# mkdir mysql/data
[root@localhost local]# groupadd mysql
[root@localhost local]# useradd -r -g mysql mysql
[root@localhost local]# chown -R mysql:mysql /usr/local/mysql/
[root@localhost local]# chmod -R 755 /usr/local/mysql/
[root@localhost local]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

4.初始化mysql

系统会生成mysql随机root密码,记住初始化root密码,例如本次密码: td_tmJp?h01j

[root@localhost local]# cd mysql/bin/
[root@localhost bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql --lower_case_table_names=1
2023-05-25T09:00:43.505086Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.33) initializing of server in progress as process 9443
2023-05-25T09:00:43.527682Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-05-25T09:00:44.979748Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-05-25T09:00:46.966676Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: td_tmJp?h01j
[root@localhost bin]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

5.修改配置文件

[root@localhost bin]# touch /etc/my.cnf
[root@localhost bin]# vim /etc/my.cnf 
[root@localhost bin]# chmod 644 /etc/my.cnf
[root@localhost bin]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.. SUCCESS! 
[root@localhost bin]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

配置文件如下:

[client]
port = 3306
socket = /usr/local/mysql/data/mysql.sock
default-character-set = utf8mb4

[mysql]  
default-character-set = utf8mb4

[mysqld]  
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
init_connect = 'SET NAMES utf8mb4'

port = 3306
socket = /usr/local/mysql/data/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
datadir = /usr/local/mysql/data
lower_case_table_names=1
innodb_strict_mode=0
sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45

6.设置软连接并重启mysql

[root@localhost bin]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@localhost bin]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
[root@localhost bin]# ln -s /usr/local/mysql/mysql.sock /var/mysql.sock
[root@localhost bin]# 
[root@localhost bin]# service mysql restart
Shutting down MySQL. SUCCESS! 
Starting MySQL. SUCCESS! 
[root@localhost bin]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

7.使用初始密码登录mysql

[root@localhost 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.33

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> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

8.修改初始密码,并设置远程登录

mysql> alter user 'root'@'localhost' identified by 'Eshop@2023!';
mysql> 
mysql> use mysql;
Database changed
mysql>
mysql> update user set user.Host='%' where user.User='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> 
mysql> CREATE USER 'eshop'@'%' IDENTIFIED BY 'Eshop@2023!';
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL PRIVILEGES ON `master\-%` . * TO 'eshop'@'%';
Query OK, 0 rows affected (0.00 sec)

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

mysql> 
mysql> exit
Bye
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

授予其他用户部分数据库权限,比如授予eshop用户以master开头的数据库权限使用如下命令

GRANT ALL PRIVILEGES ON `master\-%` . * TO 'eshop'@'%';
  • 1

9.关闭防火墙,关闭防火墙开机自启动

[root@localhost bin]# 
[root@localhost 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 Thu 2023-05-25 16:31:11 CST; 54min ago
     Docs: man:firewalld(1)
 Main PID: 807 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─807 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

May 25 16:31:09 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
May 25 16:31:11 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
May 25 16:31:11 localhost.localdomain firewalld[807]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a futu...ing it now.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost bin]# 
[root@localhost bin]# systemctl stop firewalld.service
[root@localhost bin]# 
[root@localhost bin systemctl list-unit-files | grep firewalld.service
firewalld.service                             enabled 
[root@localhost bin]# 
[root@localhost 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.
[root@localhost bin]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

10.设置mysql开机启动

mysqld 3.4.5都显示on为开机启动设置成功

[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# chmod +x /etc/init.d/mysqld
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@localhost ~]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

11.链接测试

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/664418
推荐阅读
相关标签
  

闽ICP备14008679号