MySQL安装
需要将MySQL官方的Repo加到CentOS的repo里面
执行命令:
sudo rpm -ivh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo yum install mysql-server sudo yum install mysql-devel # 此时连接MySQL没有密码,所以不能正确连接,切换root权限 systemctl stop mysql find / -name my*.cnf # 找到 /etc/my.cnf /usr/share/doc/mysql-community-server-5.6.33/my-default.cnf /usr/share/mysql/my-default.cnf # 编辑 vim /usr/share/mysql/my-default.cnf # 在my.cnf文件的[mysqld]下添加 skip-grant-tables # 执行命令 systemctl start mysql mysql -u root update mysql.user set password=PASSWORD('密码') where user='root'; flush privileges; exit; systemctl restart mysql
参考:CentOS7安装MySQL,还未设置密码的情况下无法进入mysql
另外一种方法:
# service mysqld stop 然后: # mysqld_safe --skip-grant-tables 启动mysql: # service mysqld start mysql -u root mysql> use mysql mysql> UPDATE user SET Password=PASSWORD('xxx') WHERE user='root'; mysql> flush privileges; mysql>\q