更改密码
1、mysql -u root -p
2、Enter password:***
3、mysql>use mysql #选择数据库
4、Database changed
5、mysql>UPDATE user SET password=PASSWORD("新密码") WHERE user='你的用户名'
6、mysql>FLUSH PRIVILEGES
7、mysql>quit
更改用户名:
1、mysql -u root -p
2、Enter password:***
3、mysql>use mysql #选择数据库
4、Database changed
5、mysql>update user set user="新用户名" where user="root"#将用户名为root的改为新用户名
6、mysql>flush privileges#刷新权限
7、mysql> exit
扩展资料:
mysql常用命令:
安装(基于centos)
yum -y install mariadb mariadb-server #centos7版本
yum -y install mysql mysql-server #centos7以下版本
启动
service mysqld start #开启 centos7以下版本
chkconfig mysqld on #设置开机自启
OR
systemctl start mariadb #centos7
systemctl enable mariadb
设置密码
1 、mysqladmin -u root -p123 password '1234' #修改root用户密码
2、进入mysql库修改user表
mysql>use mysql
mysql>update user set password=password('你的密码') where user='root'
mysql>flush privileges
登录
mysql #本地登录,默认用户root,空密码,用户为root@127.0.0.1
mysql -uroot -p1234 #本地登录,指定用户名和密码,用户为root@127.0.0.1
mysql -uroot P端口号 -h 192.168.31.95 -p密码 #远程登录,用户为root@192.168.31.95
查看
ps aux |grep mysqld #查看进程
netstat -an |grep 3306 #查看端口
1、编辑MySQL配置文件:windows环境中:%MySQL_installdir%\my.ini //MySQL安装目录下的my.ini配置文件。
linux环境中:/etc/my.cnf
在[MySQLd]配置段添加如下一行:skip-grant-tables
保存退出编辑。
2、然后重启MySQL服务
windows环境中:
net stop MySQL
net start MySQL
linux环境中:
/etc/init.d/MySQLd restart
3、设置新的ROOT密码
然后再在cmd命令行下执行:
MySQL -uroot -p MySQL
要求输入密码时直接回车无需密码即可进入数据库了。
现在我们执行如下语句把root密码更新为 123456:
update user set password=PASSWORD("123456") where user='root'
quit 退出MySQL。
4、还原配置文件并重启服务
然后修改MySQL配置文件把刚才添加的那一行(skip-grant-tables)删除。
再次重起MySQL服务,即可
二.修改MySQL的用户名和密码:(未证实)
方法一:(适用于管理员或者有全局权限的用户重设其它用户的密码)
进入命令行模式
mysql -u root mysql
mysql>UPDATE user SET password=PASSWORD("new password") WHERE user='name'
mysql>FLUSH PRIVILEGES
mysql>QUIT
方法二:(应用同上,只是方法不同)
mysql -u root mysql
mysql>SET PASSWORD FOR name=PASSWORD('new password')
mysql>QUIT
最后必杀技:
mysqladmin -u root "old password" "new password"
注:以上name请用你的用户名来替代,new password请输入你想要设置的密码。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)