首页 > 解决方案 > 使用 SSH 在 CentOS 上恢复 MYSQL 数据库时遇到问题

问题描述

我只需要更改 Godaddy 的 [专用 CentO] 服务器。

使用 FTP 将数据库备份文件上传.sql到站点后,我使用 SSH 连接到我的站点。

使用 su - 命令更改为超级用户后,我尝试使用以下代码恢复我的数据库:

[root@sXXX.XXX.XXX.XXX ~]# mysql -u alaskasl_destiny -p alaskasl_freakout < /home/alaskasl/backup/databases/alaskasl_freakout.sql

我得到以下ERROR 1044 (42000): Access denied for user 'alaskasl_destiny'@'localhost' to database 'alaskasl_freakout'

我无法弄清楚我做错了什么。这个命令过去一直对我有用

标签: mysqlcentos6

解决方案


First and foremost, if alasas1... is your real username, I would replace it with 'username'. Never give that info out, especially on a public place like Stackoverflow.

That said, a few things to check 1. You need to know the root user's login credentials for this new mysql instance. If this is a new setup the user is root with no password, so you should be able to use the following command:

$ mysql -u root
  1. Once you do get in to mysql, you will see a prompt similar to: mysql> at that prompt you can type

    mysql> show databases;

and a list of databases will display. Does the database you expect to be in there in there?

if not, here is what you need to do:

mysql> CREATE DATABASE 'database_name';
mysql> CREATE USER 'username' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.database_name TO 'username';
mysql> exit

At this point what you did was create the database, create a user with a password in mysql, and granted access to that database for that user. Once you type exit, you should now be back at the command prompt.

Now you can run mysql -u username -p database_name < /path/to/sql_file.sql


推荐阅读