如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?
我有一个phpmyadmin设置以及,phpmyadmin会自动更新?
如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?
我有一个phpmyadmin设置以及,phpmyadmin会自动更新?
当前回答
这就是我的解决方案。我在Ubuntu 18.04工作: https://stackoverflow.com/a/46076838/2400373
但是重要的是最后一步的改变:
UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='localhost';
其他回答
该任务指导用户在Ubuntu操作系统下设置/修改/重置MySQL root密码。在终端中输入以下行。
停止MySQL服务器:sudo /etc/init.d / mysql停止 (在某些情况下,如果/var/run/mysqld不存在,你必须首先创建它:sudo mkdir -v /var/run/mysqld && sudo chown mysql /var/run/mysqld 启动mysqld配置:sudo mysqld——skip-grant-tables & 以root身份登录MySQL: MySQL -u root MySQL 用你的新密码替换YOURNEWPASSWORD:
MySQL < 8.0
UPDATE mysql.user SET Password = PASSWORD('YOURNEWPASSWORD') WHERE User = 'root';
FLUSH PRIVILEGES;
如果你的MySQL使用新的认证插件,你将需要使用:update user set plugin="mysql_native_password" where user ='root';在冲洗特权之前。
注意:在某些版本,如果密码列不存在,你可能想尝试: UPDATE user SET authentication_string=password('YOURNEWPASSWORD') WHERE user='root';
注意:这种方法不是最安全的重置密码的方法,但它是有效的。
对于MySQL >= 8.0
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YOURNEWPASSWORD';
FLUSH PRIVILEGES;
最后一步:
正如@lambart的评论中所提到的,你可能需要杀死你启动的临时无密码mysql进程,即sudo killall -9 mysqld,然后启动正常的守护进程:sudo service mysql start
引用:
该任务指导用户在Ubuntu Linux下设置/修改/重置MySQL root密码 如何重置Root用户密码(v5.6) 如何重置Root用户密码(v8.0)
这就像我为Ubuntu 16.04做的一样。 完全归功于下面的链接,因为我从那里得到了它。 [https://coderwall.com/p/j9btlg/reset-the-mysql-5-7-root-password-in-ubuntu-16-04-lts] [1]
停止MySQL
sudo service mysql stop
制作MySQL服务目录。 Sudo mkdir /var/run/mysqld
赋予MySQL用户写入服务目录的权限。
sudo chown mysql: /var/run/mysqld
手动启动MySQL,不需要权限检查或联网。
sudo mysqld_safe --skip-grant-tables --skip-networking &
无需密码即可登录。
mysql -uroot mysql
更新root用户密码。 确保下面的查询至少更新了根帐户。 如果您愿意,进行一些选择并检查现有的值
UPDATE mysql.user SET
authentication_string=PASSWORD('YOURNEWPASSWORD'),
plugin='mysql_native_password' WHERE User='root';
EXIT;
关闭MySQL。
sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown
正常启动MySQL服务。
sudo service mysql start
正如mysql文档中password()函数所说:
此函数在MySQL 8.0.11中被移除。
这将使mysql v8.0.11及更新版本的所有现有答案都失效。
根据mysql文档,重置root密码的新通用方法如下:
The preceding sections provide password-resetting instructions specifically for Windows and Unix and Unix-like systems. Alternatively, on any platform, you can reset the password using the mysql client (but this approach is less secure): Stop the MySQL server if necessary, then restart it with the --skip-grant-tables option. This enables anyone to connect without a password and with all privileges, and disables account-management statements such as ALTER USER and SET PASSWORD. Because this is insecure, if the server is started with the --skip-grant-tables option, it enables --skip-networking automatically to prevent remote connections. Connect to the MySQL server using the mysql client; no password is necessary because the server was started with --skip-grant-tables: shell> mysql In the mysql client, tell the server to reload the grant tables so that account-management statements work: mysql> FLUSH PRIVILEGES; Then change the 'root'@'localhost' account password. Replace the password with the password that you want to use. To change the password for a root account with a different host name part, modify the instructions to use that host name. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass'; You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally (without the --skip-grant-tables and --skip-networking options).
关于这个话题的大多数答案都过时了;在写这个答案之前,MySQL发生了两个主要的变化:
1-用户表中的“Password”字段已被“authentication_string”列取代。
2-“Password”加密功能:Password(“of some text”)已弃用。
更多信息请参考此链接:dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
设置MySQL密码
停止MySQL数据库服务
sudo /etc/init.d/mysql stop
创建一个新的mysqld目录
Sudo mkdir /var/run/mysqld/
给予mysql用户访问权限
Sudo chown mysql /var/run/mysqld/
以安全模式启动MySQL…
Sudo mysqld_safe—skip-grant-tables &
无需密码登录数据库服务器
Sudo mysql -u root
使用默认的mysql数据库
使用mysql;
修改root密码
update user set authentication_string=PASSWORD(" new_passwor_here ") where user ='root';
保存更改 冲洗特权; 退出; 停止MySQL安全模式,启动MySQL默认服务
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start
使用root新密码重新登录MySQL数据库
-u root -p
***来源:https://websiteforstudents.com/resetting-mysql-root-password-on-ubuntu-16-04-17-10-and-18-04-lts/