CentOS安装Mysql
环境准备
虚拟机安装CentOS
下载并安装xshell、xftp
下载MySQL
安装MySQL命令
查看系统中有无MySQL
rpm -qa|grep mysql
查看系统中有无mariadb
rpm -qa | grep mariadb
卸载mariadb
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
进入/usr/local/目录
cd /usr/local/
查看目录下内容
ll
创建mysql目录
mkdir mysql
进入mysql目录
cd mysql
解压mysql
tar -xvf mysql-8.0.26-1.el7.x86_64.rpm-bundle.tar
查看目录下内容
ll
mysql-8.0.26-1.el7.x86_64.rpm-bundle.tar mysql-community-client-8.0.26-1.el7.x86_64.rpm mysql-community-client-plugins-8.0.26-1.el7.x86_64.rpm mysql-community-common-8.0.26-1.el7.x86_64.rpm mysql-community-devel-8.0.26-1.el7.x86_64.rpm mysql-community-embedded-compat-8.0.26-1.el7.x86_64.rpm mysql-community-libs-8.0.26-1.el7.x86_64.rpm mysql-community-libs-compat-8.0.26-1.el7.x86_64.rpm mysql-community-server-8.0.26-1.el7.x86_64.rpm mysql-community-test-8.0.26-1.el7.x86_64.rpm
依次安装
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
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
安装完成后要初始化数据库
mysqld --initialize --console
chown -R mysql:mysql /var/lib/mysql/
启动mysql
systemctl start mysqld
查看初始密码
cat /var/log/mysqld.log | grep password
登录进数据库
mysql -u root -p
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root' PASSWORD EXPIRE NEVER; 命令修改加密规则,MySql8.0 版本 和 5.0 的加密规则不一样,而现在的可视化工具只支持旧的加密方式。
通过以下命令,进行远程访问的授权
create user 'root'@'%' identified with mysql_native_password by 'root';
grant all privileges on *.* to 'root'@'%' with grant option;
命令刷新修该后的权限
flush privileges;
通过以下命令,关闭 firewall(防火墙)
systemctl stop firewalld.service;
systemctl disable firewalld.service;
systemctl mask firewalld.service;
退出 MySQL命令
exit;
快捷方式
CTRL+D