参考链接:https://www.cnblogs.com/ljysy/p/10324854.html
下载与安装MySQL:
这里采用Yum管理好了各种rpm包的依赖,能够从指定的服务器自动下载RPM包并且安装,所以在安装完成后必须要卸掉,否则会自动更新。
1.安装MySQL官方的yum repository
[[email protected] ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
2.下载rpm包
[[email protected] ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
3.安装MySQL服务
[[email protected] ~]# yum -y install mysql-community-server
最后会出现个complete!
4.启动MySQL服务
[[email protected] ~]# systemctl start mysqld.service
看到类似下面的界面,或者以Starting MySqL server.. started MysqlServer..结尾的就成功启动了
还有几个关于MySQL常用的命令:
重启:systemctl restart mysqld.service 停止:systemctl stop mysqld.service 查看状态:systemctl status mysqld.service
关于登录MySQL:
登录命令:
[[email protected] ~]# mysql -u root -p
意思就是用root用户登录,然后准备输入密码
初次登陆先 查看MySql默认密码
[[email protected] ~]# grep ‘temporary password‘ /var/log/mysqld.log
修改数据库密码
由于set password for root @localhost=password(‘passwd‘); 可能会报错
MySQL 5.7 中 Your password does not satisfy the current policy requirements.
问题
set global validate_password_policy=0;
set global validate_password_length=4;
上面两个命令搞定 开始设置自己的密码:
set password for root @localhost=password(‘passwd‘);
一些常用命令
# 重启MySql服务 [[email protected] ~]# service mysqld restart # 查看MySql版本 [[email protected] ~]# yum repolist all | grep mysql # 查看当前的启动的 MySQL 版本 [[email protected] ~]# yum repolist enabled | grep mysql # 通过Yum来安装MySQL,会自动处理MySQL与其他组件的依赖关系 [[email protected] ~]# yum install mysql-community-server # 查看MySQL安装目录 [[email protected] ~]# whereis mysql # 启动MySQL服务 [[email protected] ~]# systemctl start mysqld # 查看MySQL服务状态 [[email protected] ~]# systemctl status mysqld # 关闭MySQL服务 [[email protected] ~]# systemctl stop mysqld # 测试MySQL是否安装成功 [[email protected] ~]# mysql # 查看MySql默认密码 [[email protected] ~]# grep ‘temporary password‘ /var/log/mysqld.log # 查看所有数据库 mysql>show databases; # 退出登录数据库 mysql>exit; # 查看所有数据库用户 mysql>SELECT DISTINCT CONCAT(‘User: ‘‘‘,user,‘‘‘@‘‘‘,host,‘‘‘;‘) AS query FROM mysql.user
原文地址:https://www.cnblogs.com/manmanchanglu/p/12164245.html