1.下载mysql
在最后添加:
重启mysql
停掉mysql,将原来的my.cnf文件删除原来添加的那一行,重启.
有的时候可能在操作的时候出现:
关于查询mysql用户权限语句:
查看MYSQL数据库中所有用户
MySQL-5.6.33-1.linux_glibc2.5.x86_64.rpm-bundle.tar
2.解压
tar -xf MySQL-5.6.33-1.linux_glibc2.5.x86_64.rpm-bundle.tar
3.卸载当前系统的mysql-libs
yum remove mysql-libs
4.安装mysql
rpm -ivh Mysql-*.rpm
5.启动mysql
/etc/init.d/mysql start
6.修改密码
#1.停止mysql数据库
/etc/init.d/mysqld stop搜索
#2.执行如下命令
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
#3.使用root登录mysql数据库
mysql -u root mysql
#4.更新root密码
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
#最新版MySQL请采用如下SQL:
mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';
#5.刷新权限
mysql> FLUSH PRIVILEGES;
#6.退出mysql
mysql> quit
#7.重启mysql
/etc/init.d/mysqld restart
#8.使用root用户重新登录mysql
mysql -uroot -p
Enter password: <输入新设的密码newpassword>
有的时候可能上面一步是不行的(目前我碰到的是在centos7下安装mysql5.7版本出现的),那么可以执行planB:
vim /etc/my.cnf
在最后添加:
skip-grant-tables
重启mysql
mysql -u root
正常登陆
更新root密码:
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
#最新版MySQL请采用如下SQL:
mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';
停掉mysql,将原来的my.cnf文件删除原来添加的那一行,重启.
有的时候可能在操作的时候出现:
mysql> create database ****;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
解决方案:
mysql> SET PASSWORD = PASSWORD('newpassword');
Query OK, 0 rows affected (0.03 sec)
mysql> create database ****;
Query OK, 1 row affected (0.00 sec)
如果需要远程登陆:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
mysql> FLUSH PRIVILEGES;
PS:强烈不建议这样做,最好指定IP或者iptables写好规则,否则会有安全隐患!!!!!
关于查询mysql用户权限语句:
查看MYSQL数据库中所有用户
mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
查看数据库中具体某个用户的权限
way 1.
mysql> show grants for 'user'@'%';
way 2.
mysql> select * from mysql.user where user='user' \G