我一直在按照手册在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
然后我做了
cd ~/Desktop/iPDC-v1.3.1/DBServer-1.1
mysql -uroot -proot <"Db.sql"
我最终得到以下错误消息。
错误1045(28000):拒绝访问用户'root'@'localhost'(使用密码:YES)
我该如何修复它并继续?
在最近的MySQL版本中,MySQL中没有任何密码。用户表。
所以你需要执行ALTER USER。将这一行命令放入文件中。
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
并以init文件的形式执行(以root或mysql用户):
mysqld_safe --init-file=/home/me/mysql-init &
MySQL服务器需要停止才能启动mysqld_safe。
另外,加载这个init文件的AppArmor权限可能也有问题。阅读更多在AppArmor和MySQL。
如果其他答案都不适合您,并且您收到了以下错误:
mysqld_safe Logging to '/var/log/mysql/error.log'.
mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
[1]+ Exit 1 sudo mysqld_safe --skip-grant-tables
按照以下命令依次执行,直到重置密码:
# Stop your server first
sudo service mysql stop
# Make the MySQL service directory.
sudo mkdir /var/run/mysqld
# Give MySQL permission to work with the created directory
sudo chown mysql: /var/run/mysqld
# Start MySQL, without permission and network checking
sudo mysqld_safe --skip-grant-tables --skip-networking &
# Log in to your server without any password.
mysql -u root mysql
# Update the password for the root user:
UPDATE mysql.user SET authentication_string=PASSWORD('YourNewPasswordBuddy'), plugin='mysql_native_password' WHERE User='root' AND Host='localhost';
# If you omit (AND Host='localhost') section, it updates
# the root password regardless of its host
FLUSH PRIVILEGES;
EXIT;
# Kill the mysqld_safe process
sudo service mysql restart
# Now you can use your new password to log in to your server
mysql -u root -p
# Take note for remote access. You should create a remote
# user and then grant all privileges to that remote user
你必须重设密码!Mac OS X(已测试并正在运行)和Ubuntu的步骤:
停止使用MySQL
sudo service mysql stop
or
sudo /usr/local/mysql/support-files/mysql.server stop
以安全模式启动:
sudo mysqld_safe --skip-grant-tables --skip-networking
(上面一行是整个命令)
这将是一个持续的命令,直到进程结束,所以打开另一个shell/终端窗口,登录没有密码:
mysql -u root
mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
根据@IberoMedia的评论,对于新版本的MySQL,该字段被称为authentication_string:
mysql> UPDATE mysql.user SET authentication_string =PASSWORD('password') WHERE User='root';
启动MySQL使用:
sudo service mysql start
or
sudo /usr/local/mysql/support-files/mysql.server start
你的新密码是“password”。
注意:对于MySQL > 5.7版本,请尝试以下操作:
update mysql.user set authentication_string='password' where user='root';