卸载mariadb
解决安装mysql与mariadb冲突问题(卸载干净mariadb)_何妨徐行的博客-CSDN博客
安装rpm包前可能需要的命令:
yum install openssl-devel用于管理rpm包的工具
yum install lrzsz -y 文件传输缺乏rz
下载安装包
去mysql官网 把rpm包不管是wget 还是手动上传都行给整到liunx服务器上
创建目录,并解压
mkdir mysql tar -xvf mysql-8.0.26-1.el7.x86_64.rpm-bundle.tar -C mysql
安装mysql的安装包
cd mysql rpm -ivh mysql-community-common-8.0.26-1.el7.x86_64.rpm rpm -ivh mysql-community-client-plugins-8.0.26-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-8.0.26-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-compat-8.0.26-1.el7.x86_64.rpm yum install openssl-devel rpm -ivh mysql-community-devel-8.0.26-1.el7.x86_64.rpm rpm -ivh mysql-community-client-8.0.26-1.el7.x86_64.rpm rpm -ivh mysql-community-server-8.0.26-1.el7.x86_64.rpm
如果报错
[root@iZ2zefj8x9bih185ymxnj7Z mysql]# rpm -ivh mysql-community-server-8.0.26-1.el7.x86_64.rpm
warning: mysql-community-server-8.0.26-1.el7.x86_64.rpm: Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libaio.so.1()(64bit) is needed by mysql-community-server-8.0.26-1.el7.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-8.0.26-1.el7.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-8.0.26-1.el7.x86_64
补上
yum install libaio
运行以下命令,启动并设置开机自启动MySQL服务。
sudo systemctl start mysqld
sudo systemctl enable mysqld
其他
systemctl start mysqld
systemctl restart mysqld
systemctl stop mysqld
查询自动生成的root用户密码
grep 'temporary password' /var/log/mysqld.log
命令行执行指令 :
mysql -u root -p
然后输入上述查询到的自动生成的密码, 完成登录 .
修改root用户密码
登录到MySQL之后,需要将自动生成的不便记忆的密码修改了,修改成自己熟悉的便于记忆的密码。
ALTER USER 'root'@'localhost' IDENTIFIED BY '1234';
执行上述的SQL会报错,原因是因为设置的密码太简单,密码复杂度不够。我们可以设置密码的复杂度为简单类型,密码长度为4。
set global validate_password.policy = 0; set global validate_password.length = 4;
降低密码的校验规则之后,再次执行上述修改密码的指令。
创建用户
默认的root用户只能当前节点localhost访问,是无法远程访问的,我们还需要创建一个账户,用户远程访问
create user 'dk'@'%' IDENTIFIED WITH mysql_native_password BY '1234';
并给root用户分配权限
grant all privileges on *.* to 'dk';
刷新权限
flush privileges;