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