Linux服务器中安装Mysql数据库并设置密码

网址
1.安装参考此
https://blog.csdn.net/qq496013218/article/details/80355463?ops_request_misc=&request_id=&biz_id=102&utm_term=%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8sql%E5%AE%89%E8%A3%85&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-3-80355463
2.修改密码参考此
https://blog.csdn.net/vv19910825/article/details/82979563

安装正式
1.检查系统有没有自带mysql
rpm -qa | grep mysql

2.一般情况是没有的,但如果有,就卸载
rpm -e --nodeps mysql

3.(1)下载https://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm
安装rpm命令: rpm -ivh mysql57-community-release-el7-11.noarch.rpm
(2)安装MySQL源
命令:yum -y install mysql57-community-release-el7-8.noarch.rpm

     输入以下命令查看MySQL安装情况:yum repolist enabled | grep mysql.*

4.安装MySQL Server
yum install mysql-community-server

5.启动MySQL Server
systemctl start mysqld

6.查看MySQL状态及端口使用情况
systemctl status mysqld
netstat -apn|grep 3306

7.找到my.cnf文件
whereis my.cnf
在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程

8.重启MySQL
systemctl restart mysqld.service

9.进入到终端当中,敲入 mysql -u root -p 命令然后回车,当需要输入密码时,直接按enter键,便可以不用密码登录到数据库当中
mysql> update user set password=password(“ning”) where user=“root”;
mysql> flush privileges;
mysql> quit

//上面不行试试这个
mysql> set password=password(“ning”) where user=“root”;
10.编辑my.cnf,去掉刚才添加的内容,然后重启MySQL。大功告成!

你可能感兴趣的:(Linux)