1.新建文件夹mysql
cd /usr/local
mkdir mysql
cd mysql
2..配置yum仓库
1.更新密钥
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
2.安装mysql yum仓库
rpm -Uvh http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
3.yum安装mysql
yum search mysql 进行搜索
4.复制上面横线,执行如下命令
yum install mysql-community-server.x86_64
5.设置开机自启动
systemctl start mysqld #启动mysql
systemctl enable mysqld # 开机自启 --enable
6.检查状态
systemctl status mysqld
7.启动服务
systemctl status mysqld
systemctl // 是linux系统中用于管理系统服务的命令行工具
1.statrt // 启动服务 //systemctl start mysqld
2.stop // 停止服务 systemctl stop mysqld
3.restart // 重启服务
4.status // 查看服务状态
ps :启动时如果报
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
解决办法:
ps -aux|grep mysql
kill 杀死已经启动的mysql进程
kill 进程号
8.查看密码
grep "password" /var/log/mysqld.log
或者
grep "temporary password" /var/log/mysqld.log
9.进入mysql
将上一步得到的密码复制到-p后
mysql -u root -p
10.设置密码
// xxx填密码
set password for 'root'@'localhost'=password('xxxxx');
alter user 'root'@'localhost' identified by '你想更改的密码';
11.刷新使密码生效
flush privileges;
12.运行quit退出,之后再输入mysql -u root -p和密码检测是否完成
ps:允许远程连接
use mysql; // 先使用mysql数据库
update user set host = '%' where user = 'root'; //修改可以使root远程连接
select host, user from user;
flush privileges; //刷新