centos7 安装mysql-community-5.7.33
Posted 逃跑的沙丁鱼
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7 安装mysql-community-5.7.33相关的知识,希望对你有一定的参考价值。
目录
1 下载
https://downloads.mysql.com/archives/community/
2 检查系统总是否原有mysql如果有删除
[liucf@node1 ~]$ rpm -aq | grep mysql
mysql-cluster-community-client-7.6.17-1.el7.x86_64
mysql-cluster-community-server-7.6.17-1.el7.x86_64
mysql-cluster-community-common-7.6.17-1.el7.x86_64
mysql-cluster-community-libs-7.6.17-1.el7.x86_64
删除历史无用MySQL
[liucf@node1 ~]$ sudo rpm -e --nodeps mysql-cluster-community-server-7.6.17-1.el7.x86_64 mysql-cluster-community-common-7.6.17-1.el7.x86_64 mysql-cluster-community-libs-7.6.17-1.el7.x86_64 mysql-cluster-community-client-7.6.17-1.el7.x86_64
删除遗留的mysql 文件
sudo find / -name mysql
找到后删除,不然后可能不干净的环境,安装失败
3 上传解压mysql tar 包
[liucf@node1 softfile]$ tar -xvf mysql-5.7.33-1.el7.x86_64.rpm-bundle.tar -C ./mysql
mysql-community-client-5.7.33-1.el7.x86_64.rpm
mysql-community-common-5.7.33-1.el7.x86_64.rpm
mysql-community-devel-5.7.33-1.el7.x86_64.rpm
mysql-community-embedded-5.7.33-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.33-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.33-1.el7.x86_64.rpm
mysql-community-libs-5.7.33-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.33-1.el7.x86_64.rpm
mysql-community-server-5.7.33-1.el7.x86_64.rpm
mysql-community-test-5.7.33-1.el7.x86_64.rpm
4 安装perl
[liucf@node1 mysql]$ sudo yum install perl -y
因为mysql的server端须要perl语言的支持,所以咱们还须要在系统中安装perl支持:
[liucf@node1 mysql]$ sudo yum install perl -y
[sudo] password for liucf:
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.bfsu.edu.cn
* extras: mirrors.bfsu.edu.cn
* updates: mirrors.bfsu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package perl.x86_64 4:5.16.3-297.el7 will be updated
。。。。。。。
Updated:
perl.x86_64 4:5.16.3-299.el7_9
Dependency Updated:
perl-libs.x86_64 4:5.16.3-299.el7_9
Complete!
5 rpm安装mysql服务
5.1 安装
因为咱们上面解压出来的几个rpm包有依赖关系,因此咱们须要按照顺序执行安装:
sudo rpm -ivh mysql-community-common-5.7.33-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-libs-5.7.33-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-client-5.7.33-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-server-5.7.33-1.el7.x86_64.rpm
[liucf@node1 mysql]$ rpm -ivh mysql-community-common-5.7.33-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.33-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: can't create transaction lock on /var/lib/rpm/.rpm.lock (Permission denied)
[liucf@node1 mysql]$ sudo rpm -ivh mysql-community-common-5.7.33-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.33-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-5.7.33-1.e################################# [100%]
[liucf@node1 mysql]$ sudo rpm -ivh mysql-community-libs-5.7.33-1.el7.x86_64.rpm
warning: mysql-community-libs-5.7.33-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-5.7.33-1.el7################################# [100%]
[liucf@node1 mysql]$ sudo rpm -ivh mysql-community-client-5.7.33-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.33-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-5.7.33-1.e################################# [100%]
[liucf@node1 mysql]$ sudo rpm -ivh mysql-community-server-5.7.33-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.33-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-5.7.33-1.e################################# [100%]
[liucf@node1 mysql]$
这几个包的安装完成以后,咱们的数据库也就安装完成了,有几个须要注意的地方:
- 数据库目录:/var/lib/mysql/
- 命令配置:/usr/share/mysql (mysql.server命令及配置文件)
- 相关命令:/usr/bin (mysqladmin mysqldump等命令)
- 启动脚本:/etc/rc.d/init.d/ (启动脚本文件mysql的目录)
- 系统配置:/etc/my.conf
5.2可能遇到的报错
、报错:
[liucf@node1 mysql]$ sudo rpm -ivh MySQL-server-5.6.50-1.el7.x86_64.rpm
warning: MySQL-server-5.6.50-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
file /usr/share/mysql/charsets/README from install of MySQL-server-5.6.50-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
表面看是perl 依赖实际上我的系统里是有perl 的已经安装好的,真正缺少的依赖是autoconf
然后安装autoconf 可以了
[liucf@node1 mysql]$ sudo yum -y install autoconf
继续安装mysql server 又会出现如下警告导致无法安装成功
[liucf@node1 mysql]$ sudo rpm -ivh MySQL-server-5.6.50-1.el7.x86_64.rpm
warning: MySQL-server-5.6.50-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
package MySQL-server-5.6.50-1.el7.x86_64 is already installed
file /usr/share/mysql/charsets/README from install of MySQL-server-5.6.50-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
file /usr/share/mysql/czech/errmsg.sys from install of MySQL-server-5.6.50-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
file /usr/share/mysql/danish/errmsg.sys from install of MySQL-server-5.6.50-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
这种情况是mariadb-libs-1:5.5.68-1.el7.x86_64包冲突了。把它缷掉即可。
[liucf@node1 mysql]$ yum -y remove mariadb-libs
6 运行-初始化
安装完成了,咱们须要先把mysql运行起来,这样咱们才能进行接下来的配置。
ps.强烈建议在root用户环境下进行初始化配置,方便用户和密码的建立。
如今咱们能够先看一下 /var/lib/mysql/ 目录下是否有东西,咱们能够发现这个目录下是没有东西的,或者是连mysql这个目录都没有,也就是说数据库尚未初始化。
注意:
这里我跳过了初始化root用户,或者是mysql用户的步骤,由于网上看在5.7.12上能够成功的步骤在5.7.23上却会在启动步骤报错,缘由未知。
如今咱们来配置mysql的启动,然后MySQL自己会初始化(centos7特有):
systemctl start mysqld.service
初始化后:/var/lib/mysql/目录里多了很多东西
[liucf@node1 mysql]$ sudo ls -al /var/lib/mysql/
total 122960
drwxr-x--x 5 mysql mysql 4096 May 23 13:58 .
drwxr-xr-x. 62 root root 4096 May 23 13:54 ..
-rw-r----- 1 mysql mysql 56 May 23 13:58 auto.cnf
-rw------- 1 mysql mysql 1676 May 23 13:58 ca-key.pem
-rw-r--r-- 1 mysql mysql 1112 May 23 13:58 ca.pem
-rw-r--r-- 1 mysql mysql 1112 May 23 13:58 client-cert.pem
-rw------- 1 mysql mysql 1676 May 23 13:58 client-key.pem
-rw-r----- 1 mysql mysql 436 May 23 13:58 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 May 23 13:58 ibdata1
-rw-r----- 1 mysql mysql 50331648 May 23 13:58 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 May 23 13:58 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 May 23 13:58 ibtmp1
drwxr-x--- 2 mysql mysql 4096 May 23 13:58 mysql
srwxrwxrwx 1 mysql mysql 0 May 23 13:58 mysql.sock
-rw------- 1 mysql mysql 5 May 23 13:58 mysql.sock.lock
drwxr-x--- 2 mysql mysql 8192 May 23 13:58 performance_schema
-rw------- 1 mysql mysql 1676 May 23 13:58 private_key.pem
-rw-r--r-- 1 mysql mysql 452 May 23 13:58 public_key.pem
-rw-r--r-- 1 mysql mysql 1112 May 23 13:58 server-cert.pem
-rw------- 1 mysql mysql 1680 May 23 13:58 server-key.pem
drwxr-x--- 2 mysql mysql 8192 May 23 13:58 sys
启动:
使用 service 启动:service mysqld start
使用 mysqld 脚本启动:/etc/inint.d/mysqld start
使用 safe_mysqld 启动:safe_mysqld&
中止:
使用 service 启动:service mysqld stop
使用 mysqld 脚本启动:/etc/inint.d/mysqld stop
mysqladmin shutdown
重启:
使用 service 启动:service mysqld restart
使用 mysqld 脚本启动:/etc/inint.d/mysqld restart
7 修改root密码
初始密码在 /var/log/mysqld.log 里可以看到
[liucf@node1 mysql]$ sudo cat /var/log/mysqld.log
2021-05-23T05:58:48.652950Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-23T05:58:49.356311Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-23T05:58:49.569539Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-23T05:58:49.649914Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: f1cc9c18-bb8b-11eb-a5f6-000c294d2531.
2021-05-23T05:58:49.652068Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-05-23T05:58:52.127883Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-23T05:58:52.284131Z 1 [Note] A temporary password is generated for root@localhost: 70LHdeqP?h34
2021-05-23T05:58:55.291443Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-23T05:58:55.322334Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.33) starting as process 3602 ...
2021-05-23T05:58:55.347645Z 0 [Note] InnoDB: PUNCH HOLE support available
2021-05-23T05:58:55.347797Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-05-23T05:58:55.347842Z 0 [Note] InnoDB: Uses event mutexes
2021-05-23T05:58:55.347852Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2021-05-23T05:58:55.347858Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-05-23T05:58:55.347866Z 0 [Note] InnoDB: Using Linux native AIO
2021-05-23T05:58:55.350083Z 0 [Note] InnoDB: Number of pools: 1
2021-05-23T05:58:55.350978Z 0 [Note] InnoDB: Using CPU crc32 instructions
2021-05-23T05:58:55.371896Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2021-05-23T05:58:55.466138Z 0 [Note] InnoDB: Completed initialization of buffer pool
2021-05-23T05:58:55.507096Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-05-23T05:58:55.548790Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2021-05-23T05:58:55.618232Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2021-05-23T05:58:55.618385Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2021-05-23T05:58:55.728835Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2021-05-23T05:58:55.729882Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2021-05-23T05:58:55.729905Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2021-05-23T05:58:55.748808Z 0 [Note] InnoDB: Waiting for purge to start
2021-05-23T05:58:55.799523Z 0 [Note] InnoDB: 5.7.33 started; log sequence number 2747002
2021-05-23T05:58:55.800173Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2021-05-23T05:58:55.800971Z 0 [Note] Plugin 'FEDERATED' is disabled.
2021-05-23T05:58:55.801773Z 0 [Note] InnoDB: Buffer pool(s) load completed at 210523 13:58:55
2021-05-23T05:58:55.889742Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2021-05-23T05:58:55.889801Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2021-05-23T05:58:55.890998Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-23T05:58:55.891066Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2021-05-23T05:58:55.891880Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2021-05-23T05:58:55.891931Z 0 [Note] IPv6 is available.
2021-05-23T05:58:55.891943Z 0 [Note] - '::' resolves to '::';
2021-05-23T05:58:55.891961Z 0 [Note] Server socket created on IP: '::'.
2021-05-23T05:58:55.907281Z 0 [Note] Event Scheduler: Loaded 0 events
2021-05-23T05:58:55.907887Z 0 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.7.33' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL)
[liucf@node1 mysql]$
找到密码,可以看到:
2021-05-23T05:58:52.284131Z 1 [Note] A temporary password is generated for root@localhost: 70LHdeqP?h34
[说明]“root@localhost: 123”会生成一个临时密码 70LHdeqP?h34
因为服务已经启动了,因此能够用root和这个密码登录了:
[liucf@node1 mysql]$ mysql -u root -p
Enter password: (这里粘贴临时密码,回车)
Welcome to the MySQL monitor. Commands end with ; or \\g.
Your MySQL connection id is 2
Server version: 5.7.33
Copyright (c) 2000, 2021, 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>
修改密码:
set password = password('Lcf#123456');; # Lcf#123456 是我的密码,注意太简单的密码通不过
mysql> set password = password('Lcf#123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
设置外部远程访问权限:
mysql> grant all privileges on *.* to 'root' @'%' identified by 'Lcf#123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
8 开放端口:
这里设置完以后,就能够在其余局域网内电脑上用Navicat链接一下看看能不能链接了,若是遇到带有数字的报错(非denind)的话,能够尝试开启防火墙的端口限制:
#开启3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
#刷新防火墙
firewall-cmd --reload
9 设置开机启动
Note: Forwarding request to 'systemctl enable mysqld.service'.
查看开机启动项
[liucf@node1 ~]$ sudo systemctl list-unit-files
到此安装完毕
参考:https://www.shangmayuan.com/a/ecc4df23de954c819b3d6458.html
以上是关于centos7 安装mysql-community-5.7.33的主要内容,如果未能解决你的问题,请参考以下文章