I am an electrical engineering who mainly play around with power system instead of programming. Recently, I have been following a manual to install a software suite on Ubuntu. I have no knowledge on mySQL
at all, actually. I have done the following installations on my Ubuntu.
我是一名电气工程师,主要从事电力系统,而不是编程。最近,我一直在遵循一本手册,在Ubuntu上安装一个软件套件。实际上我对mySQL一无所知。我已经在我的Ubuntu上完成了以下安装。
sudo apt-get update
sudo apt-get install mysql-server-5.5
sudo apt-get install mysql-client-5.5
sudo apt-get install mysql-common
sudo apt-get install glade
sudo apt-get install ntp
Then I do
然后我做
me@ubuntu:~/Desktop/iPDC-v1.3.1/DBServer-1.1$ mysql -uroot -proot <"Db.sql"
I ended up with the following error message.
我最后得到了以下错误消息。
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
How may I fix it and continue?
我该如何修复和继续?
17 个解决方案
#1
93
The default root password is blank (i.e. empty string) not root
. So you can just login as:
默认的根密码是空的(即空字符串),而不是根。你可以登陆
mysql -u root
You should obviously change your root password after installation
显然,您应该在安装之后更改根密码。
mysqladmin -u root password [newpassword]
In most cases you should also set up individual user accounts before working extensively with the DB as well.
在大多数情况下,您还应该在与数据库进行广泛的工作之前建立个人用户帐户。
Note: For MySQL 5.7+ please see answer from @Lahiru to this question. That contains more current information.
注意:对于MySQL 5.7+,请参见@Lahiru对这个问题的答案。这包含了更多的当前信息。
#2
104
I was able to solve this problem by executing this statement
我可以通过执行这个语句来解决这个问题。
sudo dpkg-reconfigure mysql-server-5.5
Which will change the root password.
这将更改根密码。
#3
44
You have to reset the password! steps for mac osx(tested and working) and ubuntu
你必须重置密码!mac osx(测试和工作)和ubuntu的步骤。
Stop MySQL using
停止MySQL使用
sudo service mysql stop
or
或
$ sudo /usr/local/mysql/support-files/mysql.server stop
Start it in safe mode:
安全模式启动:
$ sudo mysqld_safe --skip-grant-tables --skip-networking
(above line is the whole command)
(以上是整个命令)
This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a password:
这将是一个持续的命令,直到进程完成,所以打开另一个shell/终端窗口,登录时没有密码:
$ mysql -u root
mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
Start MySQL using:
启动MySQL使用:
sudo service mysql start
or
或
sudo /usr/local/mysql/support-files/mysql.server start
your new password is 'password'.
你的新密码是“密码”。
#4
27
if the problem still exists try to force changing the pass
如果问题仍然存在,试着强行改变通行证。
/etc/init.d/mysql stop
mysqld_safe --skip-grant-tables &
mysql -u root
Setup new MySQL root user password
设置新的MySQL根用户密码。
use mysql;
update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
flush privileges;
quit;
Stop MySQL Server:
停止MySQL服务器:
/etc/init.d/mysql stop
Start MySQL server and test it:
启动MySQL服务器并测试它:
mysql -u root -p
#5
7
Am using Ubuntu-16.04 : installed mysql - 5.7. I Had the same issue : Login denied for root user.
使用Ubuntu-16.04:安装mysql - 5.7。我遇到了同样的问题:root用户无法登录。
Tried the below steps:
尝试以下步骤:
1. dpkg --get-selections | grep mysql
(to get the version of mysql).
1。dpkg——get-select | grep mysql(获得mysql版本)。
2. dpkg-reconfigure mysql-server-5.7
2。dpkg-reconfigure mysql -服务器- 5.7
3. mysql -u root -p
3所示。mysql - u root - p
Without -p that doesn't prompt you to ask password. Once you are in, you can create a user with a password by following steps :
没有-p,不会提示您输入密码。一旦进入,您可以通过以下步骤创建一个用户密码:
CREATE USER 'your_new_username'@'your-hostname' IDENTIFIED BY 'your-password';
创建用户'your_new_username'@'your-hostname' ' '您的密码';
GRANT ALL PRIVILEGES ON *.* to 'your_new_username'@'your-hostname' WITH GRANT OPTION;
授予*的所有特权。*以“your_new_username”@“您的主机名”与GRANT选项;
Exit from the root and login from the you gave above.
从根处退出,并从您上面所提供的登录。
mysql -u <your_new_username> -p
mysql - u < your_new_username > p
For some reason still just typing mysql does not work. AT ALL. I suggest to make it a habit to use mysql -u -p.
由于某些原因,仍然只是输入mysql不起作用。在所有。我建议养成使用mysql -u -p的习惯。
#6
5
At the initial start up of the server the following happens, given that the data directory of the server is empty:
在服务器的初始启动时,会发生以下情况,因为服务器的数据目录是空的:
- The server is initialized.
- 服务器初始化。
- SSL certificate and key files are generated in the data directory.
- SSL证书和密钥文件是在数据目录中生成的。
- The validate_password plugin is installed and enabled.
- 安装并启用了validate_password插件。
- The superuser account 'root'@'localhost' is created. The password for the superuser is set and stored in the error log file.
- 创建超级用户帐户“根”@“localhost”。超级用户的密码被设置并存储在错误日志文件中。
To reveal it, use the following command:
要显示它,请使用以下命令:
shell> sudo grep 'temporary password' /var/log/mysqld.log
Change the root password as soon as possible by logging in with the generated temporary password and set a custom password for the superuser account:
通过使用生成的临时密码登录并为超级用户帐户设置一个自定义密码,尽快更改根密码:
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass5!';
#7
3
I am using mysql-5.7.12-osx10.11-x86_64.dmg in Mac OSX
我用mysql-5.7.12-osx10.11-x86_64。dmg在Mac OSX
The installation process automatically sets up a temporary password for root user. You should save the password. The password can not be recovered.
安装过程会自动为根用户设置临时密码。您应该保存密码。密码无法恢复。
Follow the instruction
按照指令
- Go to
cd /usr/local/mysql/bin/
- 去cd /usr/local/mysql/bin/
- Enter the temporary password (which would look something like, "tsO07JF1=>3")
- 输入临时密码(类似于“tsO07JF1=>3”)
- You should get mysql> prompt.
- 你应该得到mysql>提示。
- Run,
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('{YOUR_PASSWORD}');
If you wish to set your password: "root" then the command would be,SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');
- 运行,设置'root'@'localhost' =密码('{YOUR_PASSWORD}')的密码;如果您希望设置密码:“root”,那么命令将是,设置“root”@“localhost”= password(“root”)的密码;
- Run
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
- 运行ALTER USER 'root'@'localhost'密码永不过期;
- Run
exit
- 退出运行
- Run
./mysql -u root -p
- 运行。/mysql -u root -p。
- Type your password. In my case I would type, "root" (without quote)
- 输入你的密码。在我的例子中,我会输入“root”(没有引号)
- That's all.
- 这是所有。
For convenience, you should add "/usr/local/mysql/bin"
to your PATH
为了方便起见,您应该将“/usr/local/mysql/bin”添加到您的路径中。
Now from anywhere you can type ./mysql -u root -p
and then type the password and you will get mysql> prompt.
从任何地方输入。/mysql -u root -p然后输入密码,你就会得到mysql>提示符。
Hope it helps.
希望它可以帮助。
#8
3
I came across this very annoying problem and found many answers that did not work. The best solution I came across was to completely uninstall mysql and re-install it. On re-install you set a root password and this fixed the problem.
我遇到了这个非常烦人的问题,找到了很多没用的答案。我遇到的最好的解决方案是完全卸载mysql并重新安装它。在重新安装时,设置一个根密码,这就解决了问题。
sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-5.5 mysql-client-core-5.5 sudo rm -rf /etc/mysql /var/lib/mysql sudo apt-get autoremove sudo apt-get autoclean
sudo apt-get清除mysql-server mysql-client mysql-server- - -5.5 mysql-server-core-5.5 mysql-client-core-5.5 sudo rm -rf /etc/mysql /var/lib/mysql sudo apt-get autoremove sudo apt-get autoclean。
I found this code elsewhere so I take no credit for it. But it works. To install mysql after uninstalling it I think digital ocean has a good tutorial on it. Checkout my gist for this.
https://gist.github.com/JamesDaniel/c02ef210c17c1dec82fc973cac484096
我在别处发现了这段代码,所以我不相信它。但它的工作原理。在卸载mysql后,我认为数字海洋有一个很好的教程。检查我的要点。https://gist.github.com/JamesDaniel/c02ef210c17c1dec82fc973cac484096
#9
3
Please read the official documentation: Mysql: How to Reset the Root Password
请阅读官方文档:Mysql:如何重置根密码。
If you have access to terminal:
如果你有进入终端的权限:
MySQL 5.7.6 and later:
MySQL 5.7.6和后:
$ mysql
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
MySQL 5.7.5 and earlier:
MySQL 5.7.5:早些时候,
$ mysql
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
#10
1
Just one line and it solved my issue.
只有一行,它解决了我的问题。
sudo dpkg-reconfigure mysql-server-5.5
#11
1
In Ubuntu 16.04 (MySQL version 5.7.13) I was able to resolve the problem with the steps below:
在ubuntu16.04 (MySQL版本5.7.13)中,我可以用下面的步骤解决这个问题:
-
Follow the instructions from the in section B.5.3.2.2 Resetting the Root Password: Unix and Unix-Like Systems MySQL 5.7 reference manual
按照B.5.3.2.2节的说明重新设置根密码:Unix和类Unix系统MySQL 5.7参考手册。
-
When I tried #sudo mysqld_safe --init-file=/home/me/mysql-init & it failed. The error was in /var/log/mysql/error.log
当我尝试#sudo mysqld_safe—init-file=/home/me/mysql-init时,它失败了。错误发生在/var/log/mysql/error.log。
2016-08-10T11:41:20.421946Z 0 [Note] Execution of init_file '/home/me/mysql/mysql-init' started. 2016-08-10T11:41:20.422070Z 0 [ERROR] /usr/sbin/mysqld: File '/home/me/mysql/mysql-init' not found (Errcode: 13 - Permission denied) 2016-08-10T11:41:20.422096Z 0 [ERROR] Aborting
[注]init_file '/home/me/mysql/mysql-init'开始执行。文件'/home/me/mysql/mysql-init'未找到(错误代码:13 -权限被拒绝)2016-08-10t11:41:20 . 422096z0[错误]中止。
The file permission of mysql-init was not the problem, need to edit apparmor permission
mysql-init的文件权限不是问题,需要编辑器权限。
-
Edit by #sudo vi /etc/apparmor.d/usr.sbin.mysqld
编辑:sudo vi /etc/apparmor.d/usr.sbin.mysqld。
.... /var/log/mysql/ r, /var/log/mysql/** rw, # Allow user init file /home/pranab/mysql/* r, # Site-specific additions and overrides. See local/README for details. #include <local/usr.sbin.mysqld> }
-
Do #sudo /etc/init.d/apparmor reload
做# sudo /etc/init.d / apparmor对重载
-
Start mysqld_safe again try step 2 above. Check /var/log/mysql/error.log make sure there is no error and the mysqld is successfully started
再次启动mysqld_safe,尝试上面的第2步。检查/var/log/mysql/error.日志确保没有错误,mysqld已经成功启动。
-
Run #mysql -u root -p
运行#mysql -u root -p。
Enter password:
输入密码:
Enter the password that you specified in mysql-init. You should be able to log in as root now.
输入您在mysql-init中指定的密码。现在您应该能够以root身份登录。
-
Shutdown mysqld_safe by #sudo mysqladmin -u root -p shutdown
关闭mysqld_safe,由#sudo mysqladmin -u root -p关闭。
-
Start mysqld normal way by #sudo systemctl start mysql
用#sudo systemctl启动mysql,启动mysqld正常方式。
#12
1
if the problem still exists try to force changing the pass
如果问题仍然存在,试着强行改变通行证。
Stop MySQL Server (on Linux):
停止MySQL服务器(在Linux上):
/etc/init.d/mysql stop
Stop MySQL Server (on Mac OS X):
停止MySQL服务器(在Mac OS X上):
mysql.server stop
Start mysqld_safe daemon with --skip-grant-tables
启动mysqld_safe守护进程,使用-skip-grant-表。
mysqld_safe --skip-grant-tables &
mysql -u root
Setup new MySQL root user password
设置新的MySQL根用户密码。
use mysql;
update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
flush privileges;
quit;
Stop MySQL Server (on Linux):
停止MySQL服务器(在Linux上):
/etc/init.d/mysql stop
Stop MySQL Server (on Mac OS X):
停止MySQL服务器(在Mac OS X上):
mysql.server stop
Start MySQL server service and test to login by root:
启动MySQL服务器服务和测试以root用户登录:
mysql -u root -p
#13
1
I know this an old Question but i feel this might help someone. I was recently faced with the same problem but in my case, i remember my password quite alright but it kept on giving me the same error. I tried so many solutions but still none helped then i tried this
我知道这是个老问题,但我觉得这可能对某人有帮助。我最近遇到了同样的问题,但在我的情况下,我记得我的密码很好,但它不断给我同样的错误。我尝试了很多方法,但还是没有得到帮助。
mysql -u root -p
after which it asks you for a pass word like this
之后,它会向你请求一个这样的密码。
Enter password:
and then i typed in the password i used. That's all
然后输入我使用的密码。这是所有
#14
0
BY default password will be null, so you have to change password by doing below steps.
默认情况下,密码将为空,因此您必须通过以下步骤更改密码。
connect to mysql
连接到mysql
root# mysql
根# mysql
Use mysql
使用mysql
mysql> update user set password=PASSWORD('root') where User='root'; Finally, reload the privileges:
mysql>更新用户设置密码=密码('root'),用户='root';最后,重新加载权限:
mysql> flush privileges; mysql> quit
mysql >冲洗特权;mysql >退出
#15
0
In recent MySQL versions there is no password
in mysql.user
table.
在最近的MySQL版本中,MySQL中没有密码。用户表。
So you need to execute ALTER USER
. Put this one line command into the file.
所以需要执行ALTER USER。将这一行命令放入文件中。
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
And execute it as init file (as root or mysql user)
并将其作为init文件执行(作为根用户或mysql用户)
mysqld_safe --init-file=/home/me/mysql-init &
MySQL server need to be stopped to start mysqld_safe
.
需要停止MySQL服务器以启动mysqld_safe。
Also, there may be a problem with apparmor permissions to load this init file. Read more here https://blogs.oracle.com/jsmyth/entry/apparmor_and_mysql
此外,可能存在一个问题,可能出现了装载这个init文件的文件权限。阅读更多这里https://blogs.oracle.com/jsmyth/entry/apparmor_and_mysql
#16
0
The answer may sound silly, but after wasting hours of time, this is how I got it to work
答案可能听起来很傻,但在浪费了好几个小时之后,这就是我的工作方式。
mysql -u root -p
I got the error message
我收到了错误信息。
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Even though I was typing the correct password(the temporary password you get when you first install mysql)
即使我输入了正确的密码(当你第一次安装mysql时,你会得到临时密码)
I got it right when I typed in the password when the password prompt was blinking
当我输入密码时,密码提示符闪烁。
#17
0
It happens when your password is missing.
当您的密码丢失时发生。
Steps to change password when you have forgotten:
忘记密码的步骤:
-
Stop MySQL Server (on Linux):
停止MySQL服务器(在Linux上):
sudo systemctl stop mysql
-
Start the database without loading the grant tables or enabling networking:
启动数据库,无需加载授权表或启用网络:
sudo mysqld_safe --skip-grant-tables --skip-networking &
The ampersand at the end of this command will make this process run in the
background so you can continue to use your terminal and run #mysql -u root, it will not ask for password.这个命令的末尾会让这个进程在后台运行,这样你就可以继续使用你的终端并运行#mysql -u root,它不会要求密码。
If you get error like as below:
如果出现如下错误:
2018-02-12T08:57:39.826071Z mysqld_safe Directory '/var/run/mysqld' for UNIX
socket file don't exists. mysql -u root ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock' (2) [1]+ Exit 1不存在UNIX套接字文件的mysqld_safe目录'/var/run/mysqld'。mysql -u root ERROR 2002 (HY000):无法通过套接字/var/运行/mysqld/mysqld连接到本地mysql服务器。袜子'(2)[1]+出口1。
-
Make MySQL service directory.
MySQL服务目录。
sudo mkdir /var/run/mysqld
Give MySQL user permission to write to the service directory.
给MySQL用户权限写入服务目录。
sudo chown mysql: /var/run/mysqld
-
Run the same command in step 2 to run mysql in background.
在步骤2中运行相同的命令,以在后台运行mysql。
-
Run mysql -u root you will get mysql console without entering password.
运行mysql -u root您将获得mysql控制台而不输入密码。
Run these commands
运行这些命令
FLUSH PRIVILEGES;
For MySQL 5.7.6 and newer
对于MySQL 5.7.6和更新。
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
For MySQL 5.7.5 and older
对于MySQL 5.7.5和更老的。
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');
If the ALTER USER command doesn't work use:
如果ALTER USER命令不使用:
UPDATE mysql.user SET authentication_string = PASSWORD('new_password') WHERE User = 'root' AND Host = 'localhost';
Now exit
现在退出
-
To stop instance started manually
停止实例手动启动。
sudo kill `cat /var/run/mysqld/mysqld.pid`
-
Restart mysql
重新启动mysql
sudo systemctl start mysql
#1
93
The default root password is blank (i.e. empty string) not root
. So you can just login as:
默认的根密码是空的(即空字符串),而不是根。你可以登陆
mysql -u root
You should obviously change your root password after installation
显然,您应该在安装之后更改根密码。
mysqladmin -u root password [newpassword]
In most cases you should also set up individual user accounts before working extensively with the DB as well.
在大多数情况下,您还应该在与数据库进行广泛的工作之前建立个人用户帐户。
Note: For MySQL 5.7+ please see answer from @Lahiru to this question. That contains more current information.
注意:对于MySQL 5.7+,请参见@Lahiru对这个问题的答案。这包含了更多的当前信息。
#2
104
I was able to solve this problem by executing this statement
我可以通过执行这个语句来解决这个问题。
sudo dpkg-reconfigure mysql-server-5.5
Which will change the root password.
这将更改根密码。
#3
44
You have to reset the password! steps for mac osx(tested and working) and ubuntu
你必须重置密码!mac osx(测试和工作)和ubuntu的步骤。
Stop MySQL using
停止MySQL使用
sudo service mysql stop
or
或
$ sudo /usr/local/mysql/support-files/mysql.server stop
Start it in safe mode:
安全模式启动:
$ sudo mysqld_safe --skip-grant-tables --skip-networking
(above line is the whole command)
(以上是整个命令)
This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a password:
这将是一个持续的命令,直到进程完成,所以打开另一个shell/终端窗口,登录时没有密码:
$ mysql -u root
mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
Start MySQL using:
启动MySQL使用:
sudo service mysql start
or
或
sudo /usr/local/mysql/support-files/mysql.server start
your new password is 'password'.
你的新密码是“密码”。
#4
27
if the problem still exists try to force changing the pass
如果问题仍然存在,试着强行改变通行证。
/etc/init.d/mysql stop
mysqld_safe --skip-grant-tables &
mysql -u root
Setup new MySQL root user password
设置新的MySQL根用户密码。
use mysql;
update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
flush privileges;
quit;
Stop MySQL Server:
停止MySQL服务器:
/etc/init.d/mysql stop
Start MySQL server and test it:
启动MySQL服务器并测试它:
mysql -u root -p
#5
7
Am using Ubuntu-16.04 : installed mysql - 5.7. I Had the same issue : Login denied for root user.
使用Ubuntu-16.04:安装mysql - 5.7。我遇到了同样的问题:root用户无法登录。
Tried the below steps:
尝试以下步骤:
1. dpkg --get-selections | grep mysql
(to get the version of mysql).
1。dpkg——get-select | grep mysql(获得mysql版本)。
2. dpkg-reconfigure mysql-server-5.7
2。dpkg-reconfigure mysql -服务器- 5.7
3. mysql -u root -p
3所示。mysql - u root - p
Without -p that doesn't prompt you to ask password. Once you are in, you can create a user with a password by following steps :
没有-p,不会提示您输入密码。一旦进入,您可以通过以下步骤创建一个用户密码:
CREATE USER 'your_new_username'@'your-hostname' IDENTIFIED BY 'your-password';
创建用户'your_new_username'@'your-hostname' ' '您的密码';
GRANT ALL PRIVILEGES ON *.* to 'your_new_username'@'your-hostname' WITH GRANT OPTION;
授予*的所有特权。*以“your_new_username”@“您的主机名”与GRANT选项;
Exit from the root and login from the you gave above.
从根处退出,并从您上面所提供的登录。
mysql -u <your_new_username> -p
mysql - u < your_new_username > p
For some reason still just typing mysql does not work. AT ALL. I suggest to make it a habit to use mysql -u -p.
由于某些原因,仍然只是输入mysql不起作用。在所有。我建议养成使用mysql -u -p的习惯。
#6
5
At the initial start up of the server the following happens, given that the data directory of the server is empty:
在服务器的初始启动时,会发生以下情况,因为服务器的数据目录是空的:
- The server is initialized.
- 服务器初始化。
- SSL certificate and key files are generated in the data directory.
- SSL证书和密钥文件是在数据目录中生成的。
- The validate_password plugin is installed and enabled.
- 安装并启用了validate_password插件。
- The superuser account 'root'@'localhost' is created. The password for the superuser is set and stored in the error log file.
- 创建超级用户帐户“根”@“localhost”。超级用户的密码被设置并存储在错误日志文件中。
To reveal it, use the following command:
要显示它,请使用以下命令:
shell> sudo grep 'temporary password' /var/log/mysqld.log
Change the root password as soon as possible by logging in with the generated temporary password and set a custom password for the superuser account:
通过使用生成的临时密码登录并为超级用户帐户设置一个自定义密码,尽快更改根密码:
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass5!';
#7
3
I am using mysql-5.7.12-osx10.11-x86_64.dmg in Mac OSX
我用mysql-5.7.12-osx10.11-x86_64。dmg在Mac OSX
The installation process automatically sets up a temporary password for root user. You should save the password. The password can not be recovered.
安装过程会自动为根用户设置临时密码。您应该保存密码。密码无法恢复。
Follow the instruction
按照指令
- Go to
cd /usr/local/mysql/bin/
- 去cd /usr/local/mysql/bin/
- Enter the temporary password (which would look something like, "tsO07JF1=>3")
- 输入临时密码(类似于“tsO07JF1=>3”)
- You should get mysql> prompt.
- 你应该得到mysql>提示。
- Run,
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('{YOUR_PASSWORD}');
If you wish to set your password: "root" then the command would be,SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');
- 运行,设置'root'@'localhost' =密码('{YOUR_PASSWORD}')的密码;如果您希望设置密码:“root”,那么命令将是,设置“root”@“localhost”= password(“root”)的密码;
- Run
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
- 运行ALTER USER 'root'@'localhost'密码永不过期;
- Run
exit
- 退出运行
- Run
./mysql -u root -p
- 运行。/mysql -u root -p。
- Type your password. In my case I would type, "root" (without quote)
- 输入你的密码。在我的例子中,我会输入“root”(没有引号)
- That's all.
- 这是所有。
For convenience, you should add "/usr/local/mysql/bin"
to your PATH
为了方便起见,您应该将“/usr/local/mysql/bin”添加到您的路径中。
Now from anywhere you can type ./mysql -u root -p
and then type the password and you will get mysql> prompt.
从任何地方输入。/mysql -u root -p然后输入密码,你就会得到mysql>提示符。
Hope it helps.
希望它可以帮助。
#8
3
I came across this very annoying problem and found many answers that did not work. The best solution I came across was to completely uninstall mysql and re-install it. On re-install you set a root password and this fixed the problem.
我遇到了这个非常烦人的问题,找到了很多没用的答案。我遇到的最好的解决方案是完全卸载mysql并重新安装它。在重新安装时,设置一个根密码,这就解决了问题。
sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-5.5 mysql-client-core-5.5 sudo rm -rf /etc/mysql /var/lib/mysql sudo apt-get autoremove sudo apt-get autoclean
sudo apt-get清除mysql-server mysql-client mysql-server- - -5.5 mysql-server-core-5.5 mysql-client-core-5.5 sudo rm -rf /etc/mysql /var/lib/mysql sudo apt-get autoremove sudo apt-get autoclean。
I found this code elsewhere so I take no credit for it. But it works. To install mysql after uninstalling it I think digital ocean has a good tutorial on it. Checkout my gist for this.
https://gist.github.com/JamesDaniel/c02ef210c17c1dec82fc973cac484096
我在别处发现了这段代码,所以我不相信它。但它的工作原理。在卸载mysql后,我认为数字海洋有一个很好的教程。检查我的要点。https://gist.github.com/JamesDaniel/c02ef210c17c1dec82fc973cac484096
#9
3
Please read the official documentation: Mysql: How to Reset the Root Password
请阅读官方文档:Mysql:如何重置根密码。
If you have access to terminal:
如果你有进入终端的权限:
MySQL 5.7.6 and later:
MySQL 5.7.6和后:
$ mysql
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
MySQL 5.7.5 and earlier:
MySQL 5.7.5:早些时候,
$ mysql
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
#10
1
Just one line and it solved my issue.
只有一行,它解决了我的问题。
sudo dpkg-reconfigure mysql-server-5.5
#11
1
In Ubuntu 16.04 (MySQL version 5.7.13) I was able to resolve the problem with the steps below:
在ubuntu16.04 (MySQL版本5.7.13)中,我可以用下面的步骤解决这个问题:
-
Follow the instructions from the in section B.5.3.2.2 Resetting the Root Password: Unix and Unix-Like Systems MySQL 5.7 reference manual
按照B.5.3.2.2节的说明重新设置根密码:Unix和类Unix系统MySQL 5.7参考手册。
-
When I tried #sudo mysqld_safe --init-file=/home/me/mysql-init & it failed. The error was in /var/log/mysql/error.log
当我尝试#sudo mysqld_safe—init-file=/home/me/mysql-init时,它失败了。错误发生在/var/log/mysql/error.log。
2016-08-10T11:41:20.421946Z 0 [Note] Execution of init_file '/home/me/mysql/mysql-init' started. 2016-08-10T11:41:20.422070Z 0 [ERROR] /usr/sbin/mysqld: File '/home/me/mysql/mysql-init' not found (Errcode: 13 - Permission denied) 2016-08-10T11:41:20.422096Z 0 [ERROR] Aborting
[注]init_file '/home/me/mysql/mysql-init'开始执行。文件'/home/me/mysql/mysql-init'未找到(错误代码:13 -权限被拒绝)2016-08-10t11:41:20 . 422096z0[错误]中止。
The file permission of mysql-init was not the problem, need to edit apparmor permission
mysql-init的文件权限不是问题,需要编辑器权限。
-
Edit by #sudo vi /etc/apparmor.d/usr.sbin.mysqld
编辑:sudo vi /etc/apparmor.d/usr.sbin.mysqld。
.... /var/log/mysql/ r, /var/log/mysql/** rw, # Allow user init file /home/pranab/mysql/* r, # Site-specific additions and overrides. See local/README for details. #include <local/usr.sbin.mysqld> }
-
Do #sudo /etc/init.d/apparmor reload
做# sudo /etc/init.d / apparmor对重载
-
Start mysqld_safe again try step 2 above. Check /var/log/mysql/error.log make sure there is no error and the mysqld is successfully started
再次启动mysqld_safe,尝试上面的第2步。检查/var/log/mysql/error.日志确保没有错误,mysqld已经成功启动。
-
Run #mysql -u root -p
运行#mysql -u root -p。
Enter password:
输入密码:
Enter the password that you specified in mysql-init. You should be able to log in as root now.
输入您在mysql-init中指定的密码。现在您应该能够以root身份登录。
-
Shutdown mysqld_safe by #sudo mysqladmin -u root -p shutdown
关闭mysqld_safe,由#sudo mysqladmin -u root -p关闭。
-
Start mysqld normal way by #sudo systemctl start mysql
用#sudo systemctl启动mysql,启动mysqld正常方式。
#12
1
if the problem still exists try to force changing the pass
如果问题仍然存在,试着强行改变通行证。
Stop MySQL Server (on Linux):
停止MySQL服务器(在Linux上):
/etc/init.d/mysql stop
Stop MySQL Server (on Mac OS X):
停止MySQL服务器(在Mac OS X上):
mysql.server stop
Start mysqld_safe daemon with --skip-grant-tables
启动mysqld_safe守护进程,使用-skip-grant-表。
mysqld_safe --skip-grant-tables &
mysql -u root
Setup new MySQL root user password
设置新的MySQL根用户密码。
use mysql;
update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
flush privileges;
quit;
Stop MySQL Server (on Linux):
停止MySQL服务器(在Linux上):
/etc/init.d/mysql stop
Stop MySQL Server (on Mac OS X):
停止MySQL服务器(在Mac OS X上):
mysql.server stop
Start MySQL server service and test to login by root:
启动MySQL服务器服务和测试以root用户登录:
mysql -u root -p
#13
1
I know this an old Question but i feel this might help someone. I was recently faced with the same problem but in my case, i remember my password quite alright but it kept on giving me the same error. I tried so many solutions but still none helped then i tried this
我知道这是个老问题,但我觉得这可能对某人有帮助。我最近遇到了同样的问题,但在我的情况下,我记得我的密码很好,但它不断给我同样的错误。我尝试了很多方法,但还是没有得到帮助。
mysql -u root -p
after which it asks you for a pass word like this
之后,它会向你请求一个这样的密码。
Enter password:
and then i typed in the password i used. That's all
然后输入我使用的密码。这是所有
#14
0
BY default password will be null, so you have to change password by doing below steps.
默认情况下,密码将为空,因此您必须通过以下步骤更改密码。
connect to mysql
连接到mysql
root# mysql
根# mysql
Use mysql
使用mysql
mysql> update user set password=PASSWORD('root') where User='root'; Finally, reload the privileges:
mysql>更新用户设置密码=密码('root'),用户='root';最后,重新加载权限:
mysql> flush privileges; mysql> quit
mysql >冲洗特权;mysql >退出
#15
0
In recent MySQL versions there is no password
in mysql.user
table.
在最近的MySQL版本中,MySQL中没有密码。用户表。
So you need to execute ALTER USER
. Put this one line command into the file.
所以需要执行ALTER USER。将这一行命令放入文件中。
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
And execute it as init file (as root or mysql user)
并将其作为init文件执行(作为根用户或mysql用户)
mysqld_safe --init-file=/home/me/mysql-init &
MySQL server need to be stopped to start mysqld_safe
.
需要停止MySQL服务器以启动mysqld_safe。
Also, there may be a problem with apparmor permissions to load this init file. Read more here https://blogs.oracle.com/jsmyth/entry/apparmor_and_mysql
此外,可能存在一个问题,可能出现了装载这个init文件的文件权限。阅读更多这里https://blogs.oracle.com/jsmyth/entry/apparmor_and_mysql
#16
0
The answer may sound silly, but after wasting hours of time, this is how I got it to work
答案可能听起来很傻,但在浪费了好几个小时之后,这就是我的工作方式。
mysql -u root -p
I got the error message
我收到了错误信息。
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Even though I was typing the correct password(the temporary password you get when you first install mysql)
即使我输入了正确的密码(当你第一次安装mysql时,你会得到临时密码)
I got it right when I typed in the password when the password prompt was blinking
当我输入密码时,密码提示符闪烁。
#17
0
It happens when your password is missing.
当您的密码丢失时发生。
Steps to change password when you have forgotten:
忘记密码的步骤:
-
Stop MySQL Server (on Linux):
停止MySQL服务器(在Linux上):
sudo systemctl stop mysql
-
Start the database without loading the grant tables or enabling networking:
启动数据库,无需加载授权表或启用网络:
sudo mysqld_safe --skip-grant-tables --skip-networking &
The ampersand at the end of this command will make this process run in the
background so you can continue to use your terminal and run #mysql -u root, it will not ask for password.这个命令的末尾会让这个进程在后台运行,这样你就可以继续使用你的终端并运行#mysql -u root,它不会要求密码。
If you get error like as below:
如果出现如下错误:
2018-02-12T08:57:39.826071Z mysqld_safe Directory '/var/run/mysqld' for UNIX
socket file don't exists. mysql -u root ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock' (2) [1]+ Exit 1不存在UNIX套接字文件的mysqld_safe目录'/var/run/mysqld'。mysql -u root ERROR 2002 (HY000):无法通过套接字/var/运行/mysqld/mysqld连接到本地mysql服务器。袜子'(2)[1]+出口1。
-
Make MySQL service directory.
MySQL服务目录。
sudo mkdir /var/run/mysqld
Give MySQL user permission to write to the service directory.
给MySQL用户权限写入服务目录。
sudo chown mysql: /var/run/mysqld
-
Run the same command in step 2 to run mysql in background.
在步骤2中运行相同的命令,以在后台运行mysql。
-
Run mysql -u root you will get mysql console without entering password.
运行mysql -u root您将获得mysql控制台而不输入密码。
Run these commands
运行这些命令
FLUSH PRIVILEGES;
For MySQL 5.7.6 and newer
对于MySQL 5.7.6和更新。
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
For MySQL 5.7.5 and older
对于MySQL 5.7.5和更老的。
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');
If the ALTER USER command doesn't work use:
如果ALTER USER命令不使用:
UPDATE mysql.user SET authentication_string = PASSWORD('new_password') WHERE User = 'root' AND Host = 'localhost';
Now exit
现在退出
-
To stop instance started manually
停止实例手动启动。
sudo kill `cat /var/run/mysqld/mysqld.pid`
-
Restart mysql
重新启动mysql
sudo systemctl start mysql