Mysql常见更改密码方法
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) chown -R mysql.mysql /var/lib/mysql ERROR! MySQL is running but PID file could not be found 先打印MYSQL进程 ps aux | grep mysql 然后KILL进程 kill -9 pid1 pid2 … 再启动MYSQL /etc/init.d/mysqld start 再检查mysql运行状态 /etc/init.d/mysqld status 第三种:是修改过my.cnf配置出错引起 执行命令:vi /etc/my.cnf 修改内容: # The MySQL server [mysqld] port = 3306 socket = /var/lib/mysql/mysql.sock 在执行第二种命令,OK 完全移除mysql ######################################################## 1、yum remove mysql mysql-server mysql-libs compat-mysql51 2、rm -rf /var/lib/mysql 3、rm /etc/my.cnf 查看是否还有mysql软件: rpm -qa|grep mysql 如果存在的话,继续删除即可。 ######################################################## 更改初始密码 ######################################################## /etc/init.d/mysql stop cd /usr/local/mysql mysqld_safe –user=mysql –skip-grant-tables –skip-networking & mysql -u root mysql mysql > UPPATE user SET password=PASSWORD(‘newpassword’) where USER=’root’; mysql > FLUSH PRIVILEGES; mysql > quit ; /etc/init.d/mysql restart mysql -u root -p 方法1: 用SET PASSWORD命令 mysql -u root mysql> SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘newpass’); 方法2:用mysqladmin mysqladmin -u root password “newpass” 如果root已经设置过密码,采用如下方法 mysqladmin -u root password oldpass “newpass” 方法3: 用UPDATE直接编辑user表 mysql -u root mysql> use mysql; mysql> UPDATE user SET Password = PASSWORD(‘newpass’) WHERE user = ‘root’; mysql> FLUSH PRIVILEGES; ######################################################## 丢失密码修改 ######################################################## 方法1: mysqld_safe –skip-grant-tables& mysql -u root mysql mysql> UPDATE user SET password=PASSWORD(“new password”) WHERE user=’root’; mysql> FLUSH PRIVILEGES; 方法2: 1、修改mysql的配置文件(默认为/etc/my.cnf),在[mysqld]下添加一行skip-grant-tables 2、保存配置文件后,重启mysql服务 service mysqld restart 3、mysql -u root -p登录mysql,然后不输入密码直接回车,然后按照上面的流程修改密码 4、密码修改完毕,按照流程1的删除配置文件中的那行,然后重启mysql服务 ########################################################
原谅我这一生不羁放纵爱自由