腾讯云centos7安装Mysql过程,以及遇到的问题
centos7安装MySql8
有一个1核2G的腾讯云服务器和阿里云服务器,去年活动打骨折买的,才38一年。今天试着在腾讯云的centos7中安装一个mysql8,但是遇到了些问题,重复卸载几次在安装,在网上搜索了很多,写的不是很清楚。
centos7安装MySql遇到的主要问题
前期安装一直失败了的,网上查到Centos7之后对MySQL安装收费原因,在Centos中自带一个mariadb数据库替代MySql。我通过yum安装mysql先是遇到启动不了服务,卸载后重新安装后可以启动服务但是找不到初始的密码文件,又彻底删除了一次,重新安装千检查是否有mariadb,果然还有在第二次卸载没卸载掉这个。安装前是需要确定以及把mysql以及彻底删除完了!!!
1.检查是否有mariadb数据库
检查是否有mariadb命令: rpm - qa | grep mariadb
[root@VM-16-8-centos /]# rpm -qa | grep mariadb
mariadb-connector-c-config-3.1.11-2.el8_3.noarch
mariadb-backup-10.3.28-1.module_el8.3.0+757+d382997d.x86_64
mariadb-errmsg-10.3.28-1.module_el8.3.0+757+d382997d.x86_64
mariadb-server-utils-10.3.28-1.module_el8.3.0+757+d382997d.x86_64
mariadb-connector-c-3.1.11-2.el8_3.x86_64
mariadb-server-10.3.28-1.module_el8.3.0+757+d382997d.x86_64
mariadb-10.3.28-1.module_el8.3.0+757+d382997d.x86_64
mariadb-common-10.3.28-1.module_el8.3.0+757+d382997d.x86_64
mariadb-gssapi-server-10.3.28-1.module_el8.3.0+757+d382997d.x86_64
[root@VM-16-8-centos /]#
我这个查询多出来很多安装文件,需要全部删除掉。
用SSH工具MobaXterm连接腾讯云,删除掉所有mariadb文件夹(鼠标双击选中文件名后,右键复制到删除命令后,操作的快)
普通删除模式
rpm -e xxx(mysql_libs)
强力删除模式,如果上述命令删除时,提示有依赖其他文件,则可以用该命令对其进行强力删除
rpm -e --nodeps xxx(mysql_libs)
2.删除完重启一次
删除完重启一次,root下用shutdown 命令重启。
立即重启命令(root用户)
shutdown -r now
在查询一下是否还有mariadb依赖
查询mariadb依赖命令
rpm -qa | grep mariadb
此时以前的mysql和mariadb都卸载完了,可以重新在安装MySql了,以前安装成功了但是启动服务后没有初始密码文件就是这里没有卸载干净。可以重新安装了。
3.通过yum的重新安装
下载mysql安装包命令: wget +[http://地址]
wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
通过yum下载rpm包
yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
yum安装mysql
yum install mysql-community-server
启动MySQL服务器
systemctl start mysqld
MySQL的自动启动
systemctl enable mysqld
4.找到mysql存储密码文件,登录mysql
在/var/log目录下找到的mysqld.log,需要用cat mysqld.log | grep password命令或是直接查看文件。
找到了安装初始密码的文件,提示如下:
[Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
用两种命令查看了两次没有密码,发现这个root默认密码是空的,和windows系统安装客户端时遇到的情况一样,也有这种情况出现,可以重新设置密码。下面是敲的命令:
[root@VM-16-8-centos /]# cd /var/log
[root@VM-16-8-centos log]# ll
total 110036
drwxr-xr-x. 2 root root 4096 Nov 26 2019 anaconda
drwx------. 2 root root 4096 Mar 24 09:50 audit
-rw------- 1 root root 14640 Mar 27 17:56 boot.log
-rw------- 1 root root 1 Jan 28 14:16 boot.log-20200828
-rw------- 1 root root 1 Jan 28 14:16 boot.log-20201105
-rw------- 1 root root 1 Jan 28 14:16 boot.log-20210611
-rw------- 1 root root 1 Jan 28 14:16 boot.log-20210624
-rw------- 1 root root 1 Jan 28 14:16 boot.log-20210706
-rw------- 1 root root 1 Jan 28 14:16 boot.log-20210804
-rw------- 1 root root 14691 Jan 28 15:06 boot.log-20220128
-rw-rw---- 1 root utmp 14004096 Mar 27 16:27 btmp
-rw------- 1 root utmp 14848512 Mar 1 02:40 btmp-20220301
drwxr-xr-x. 2 chrony chrony 4096 Mar 2 2021 chrony
-rw-r--r-- 1 syslog adm 215217 Mar 27 17:56 cloud-init.log
-rw-r--r-- 1 root root 10771 Mar 27 17:56 cloud-init-output.log
-rw------- 1 root root 16478544 Mar 27 18:59 cron
-rw------- 1 root root 28365 Mar 27 18:57 dnf.librepo.log
-rw-r--r-- 1 root root 1 Jan 28 14:16 dnf.librepo.log-20200828
-rw------- 1 root root 1 Jan 28 14:16 dnf.librepo.log-20201105
-rw------- 1 root root 118747 Mar 27 18:57 dnf.log
-rw-r--r-- 1 root root 1 Jan 28 14:16 dnf.log-20200828
-rw------- 1 root root 1 Jan 28 14:16 dnf.log-20201105
-rw------- 1 root root 4240 Mar 27 18:57 dnf.rpm.log
-rw-r--r-- 1 root root 1 Jan 28 14:16 dnf.rpm.log-20200828
-rw------- 1 root root 1 Jan 28 14:16 dnf.rpm.log-20201105
-rw------- 1 root root 2400 Mar 27 18:57 hawkey.log
-rw------- 1 root root 1 Jan 28 14:16 hawkey.log-20210624
-rw------- 1 root root 1 Jan 28 14:16 hawkey.log-20210706
-rw------- 1 root root 1 Jan 28 14:16 hawkey.log-20210804
-rw------- 1 root root 61 Jan 28 14:16 hawkey.log-20220128
drwxr-xr-x. 2 root root 4096 Nov 26 2019 insights-client
drwxr-sr-x+ 10 root systemd-journal 4096 Jan 28 14:15 journal
-rw-r--r-- 1 root root 1671 Mar 27 17:56 kdump.log
-rw-rw-r--. 1 root utmp 292584 Mar 27 17:57 lastlog
-rw-------. 1 root root 1 Jan 28 14:16 maillog
drwxr-x--- 2 mysql mysql 4096 Mar 27 13:18 mariadb
-rw-------. 1 root root 40219041 Mar 27 18:58 messages
drwxr-x--- 2 mysql mysql 4096 Mar 27 18:57 mysql
drwx------. 2 root root 4096 Nov 26 2019 private
-rw-r--r-- 1 root root 435 Mar 27 17:56 qcloud_action.log
drwxr-xr-x. 2 root root 4096 May 21 2021 qemu-ga
drwx------. 3 root root 4096 Feb 10 2021 samba
-rw-------. 1 root root 26480455 Mar 27 18:57 secure
-rw-------. 1 root root 1 Jan 28 14:16 spooler
drwxr-x---. 2 sssd sssd 4096 Mar 27 03:13 sssd
drwxr-xr-x. 2 root root 4096 Jun 2 2021 tuned
-rw-rw-r--. 1 root utmp 18048 Mar 27 17:56 wtmp
[root@VM-16-8-centos log]# cd mysql
[root@VM-16-8-centos mysql]# ll
total 4
-rw-r----- 1 mysql mysql 1945 Mar 27 18:58 mysqld.log
[root@VM-16-8-centos mysql]# cat mysql.log
cat: mysql.log: No such file or directory
[root@VM-16-8-centos mysql]# cat mysqld.log
2022-03-27T10:58:05.321138Z 0 [System] [MY-013169] [Server] /usr/libexec/mysqld (mysqld 8.0.26) initializing of server in progress as process 10936
2022-03-27T10:58:05.332667Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-03-27T10:58:06.600239Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-03-27T10:58:08.360777Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2022-03-27T10:58:08.361215Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2022-03-27T10:58:08.501370Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2022-03-27T10:58:13.388855Z 0 [System] [MY-010116] [Server] /usr/libexec/mysqld (mysqld 8.0.26) starting as process 10998
2022-03-27T10:58:13.400986Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-03-27T10:58:13.802197Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-03-27T10:58:14.138526Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2022-03-27T10:58:14.138654Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2022-03-27T10:58:14.139654Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-03-27T10:58:14.139852Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-03-27T10:58:14.161162Z 0 [System] [MY-010931] [Server] /usr/libexec/mysqld: ready for connections. Version: '8.0.26' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution.
2022-03-27T10:58:14.161264Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/lib/mysql/mysqlx.sock
[root@VM-16-8-centos mysql]# cat mysqld.log | grep password
2022-03-27T10:58:08.501370Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@VM-16-8-centos mysql]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.26 Source distribution
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>
修改root用户登录密码
mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘Huawei@123’
重新安装后我这个root密码是空的,重新设置了一下root密码。还要给这个数据库配置一下远程连接,阿里云那个RDS数据库可以直接设置白名单,用Navicat远程连接阿里云数据库。
相应参考文章连接:
https://blog.csdn.net/qq_41389482/article/details/109711389
https://cloud.tencent.com/developer/article/1745084