首先从官网下载mysql数据库,MySQL :: Download MySQL Community Server,可以先解压后然后通过xshell上传到服务器/home/njcc/Downloads/mysql-5.7.37-1.el7.x86_64.rpm-bundle?
卸载系统自带的mariadb,过程中选择y,删除后cd到上传的mysql包下面按照顺序进行安装!
rpm -qa|grep mariadb //查看系统有没有mariadb
yum remove mysql-libs //删除
?安装过程中可能出现的问题:
1.缺少libaio? ?yum install libaio
2.缺少net-tools? ??yum install net-tools
3.缺少numactl? ? ?yum install numactl
rpm -ivh mysql-community-common-5.7.37-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.37-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.37-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.37-1.el7.x86_64.rpm
安装好之后进行初始化
mysqld --initialize #初始化后会在/var/log/mysqld.log生成随机密码
修改mysql数据库目录的所属用户及其所属的组,然后启动mysql数据库。
[root@localhost mysql]# chown mysql:mysql /var/lib/mysql -R
[root@localhost mysql]# systemctl start mysqld.service
[root@localhost mysql]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2022-02-04 05:25:42 EST; 17s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 2596 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 2572 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 2600 (mysqld)
Tasks: 27
CGroup: /system.slice/mysqld.service
└─2600 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Feb 04 05:25:41 localhost.localdomain systemd[1]: Starting MySQL Server...
Feb 04 05:25:42 localhost.localdomain systemd[1]: Started MySQL Server.
[root@localhost mysql]#
?登录mysql并修改root用户的密码(系统强制要求,否则不能操作mysql)初始登录密码可在/var/log/mysqld.log文件中找到。如果找不到可以先停掉数据库service mysqld stop然后把/var/lib/mysql 给删除掉,重启mysql服务systemctl restart mysqld,再去找临时密码:
grep 'temporary password' /var/log/mysqld.log
2022-02-04T10:48:10.496137Z 1 [Note] A temporary password is generated for root@localhost: LYs!JN.kW1lT
f)r4nJoPd2S_
重新登录数据库
mysql -uroot -p
输入生成的临时密码,此时不能复制,只能手填。
登录成功后,更改登录密码及开放权限
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; #修改密码
如果报错,输入
mysql> set global validate_password_policy=0;
然后再接着输入
mysql> set
global validate_password_length=1;
再次执行修改密码就可以了, 需要注意的是密码是6位
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';
授权其他机子登录
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
?<签名>17372799170@163.com,此为常用邮箱,前面数字加WX咨询配置方案,长期有效!品牌服务器金牌分销商。 麻烦备注下CSDN上看到的,谢谢!
|