I have a recently set up VPS with cPanel.
I've made a user and created a database, and now I would like to import a database onto it.
However, when I try I get the error message
#1044 - Access denied for user 'user'#'localhost' to database 'database'
I suspect that this can be fixed with WHM, but I do not feel like trial and error just yet.
How would I go about fixing this?
When you import a database using phpMyAdmin, normally you do so by importing a text file with a .sql extension. Here is a section of code that may be in a .sql database backup. In your example, the database you are trying to import is named database.
-- phpMyAdmin SQL Dump
-- version 2.11.9.5
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Apr 02, 2010 at 08:01 AM
-- Server version: 5.0.81
-- PHP Version: 5.2.6
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
CREATE DATABASE database;
-- --------------------------------------------------------
--
-- Table structure for table `table`
--
CREATE TABLE IF NOT EXISTS `table` (
`column1` text NOT NULL,
`column2` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
When using phpMyAdmin to attempt to import such a file, you will receive an error message similar to:
Error
SQL query:
CREATE DATABASE database;
MySQL said: Documentation
#1044 - Access denied for user 'user'#'localhost' to database 'database'
In this scenario, the cPanel username is user. Because of cPanel's database naming conventions, all database names must begin with the cPanel username followed by _. Using this format you can only creat a database named user_database.
The reason this import failed is because of the following line in the .sql file...
CREATE DATABASE database;
Again, you cannot create a database named database, however you can create a database named user_database.
If you change the line that says: CREATE DATABASE so that it creates: user_database instead of database it will again fail with the following message:
Error
SQL query:
CREATE DATABASE user_database;
MySQL said: Documentation
#1044 - Access denied for user 'user'#'localhost' to database 'user_database'
When using cPanel, databases must be created within the cPanel itself.
Here are the steps to correct thi sissue:
Create the user_database database within cPanel
Comment out the CREATE DATABASE command in my .sql file
To do this, simply change:
CREATE DATABASE database;
to
-- CREATE DATABASE database;
You are simply adding dash-dash-space to the front of the line to comment it out so that it will not be executed.
Log into phpMyAdmin, access the user_database database, and then import as normal.
Before dumping your database, grant full access to your new database user created in Cpanel by the same password of that user:
grant all on database_name.* to database_user#localhost identified by 'password';
Then you need to modify your .sql file (can use notepad++), comment out the part where says create and use the new database:
-- Database: dbname
--
-- CREATE DATABASE IF NOT EXISTS dbname DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
-- USE dbname;
then you should be able to import it to your Cpanel.
To make it official...
The file you're attempting to import probably has something that you don't have permissions for. I would check permissions, then the file you're importing.
Related
So I read somewhere that Django doesn't create the DB in production on MySQL. It only created the tables and you have to create the DB in MySQL before you can do syncdb. However, I made the mistake of doing syncdb when the database with the name in my.cnf didn't exist. And now I'm locked out of mysql. I can't log into it using mysql -u root -p. It gives me error: ERROR 1049 (42000): Unknown database
Figured it out. Just comment out the part specific to the database in which Django tried to create tables (in the file my.cnf). Then you should be able to log into MySQL.
I am trying to import my old database back into phpmyadmin after deleting it and creating a new one...steps taken....deleted database after back up....created new database with different name and received this error when trying to import
1044 - Access denied for user 'augr_2'#'%' to database 'augr_2'
After some research i found that i must change my CREATE DATABASE line in my database .sql file after amendment it looked like this
CREATE DATABASE `augr_2` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `augr_2`;
But i still keep getting this error?
this is the full error i receive
SQL query:
--
-- Database: `augr_2`
--
CREATE DATABASE `augr_2` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
MySQL said:
1044 - Access denied for user 'augr_2'#'%' to database 'augr_2'
It looks like the mysql used by the PMA doesn't have rights on the newly created db , which is normal.
Try this logged it as root
GRANT ALL ON *.* TO 'augr_2'#'%';
FLUSH PRIVILEGES;
I am not getting a clue to:
simply login to postgreSQL
Create a database
Add a table
Insert a record
Delete , update etc
These things are normally very very easy using mysql . Can someone help me setup following alternative for postgresql
a) Reset default password -- Very Clean description ,
I do not find same level of clarity for PostgreSQL
(Any documentation link is highly appreciated)
b) We know the superuser for mysql is "root" what is the same for PostgreSQL
c) from command line how to ( PostgreSQL ones ?):
mysql -uroot -proot
create database testdb;
use testdb;
create table test(id int(11) auto_increment, name varchar(20), primary key(id));
insert into test(name) values("testing one"),("testing two"),("testing three"),("testing four");
select * from test;
update test set name=concat(name,now()) where id =3;
delete from test where id =4;
drop table if exists test;
drop database if exists testdb;
EDIT MAC OS
# Default password reset
sudo mate /Library/PostgreSQL/9.2/data/pg_hba.conf
replaced (md5 with trust)
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
with
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
save
executed the Reload Configuration.app
login to postgresql without password :
$ psql -U postgres
postgres# ALTER USER postgres WITH PASSWORD 'new password';
\q
-revert back all the changes in pg_hba.conf (replace trust with md5) and save
-reload configuration
Now I can login to postgresql with new password
psql -U postgres
Password for user postgres:[my new password]
To login:
psql -d postgres_dbname -U postgres
Create Database:
create database testuser;
\c testuser; /*use testuse as mysql*/
Create Table:
create table employee (Name char(20));
Insert :
insert into employee VALUES ('XAS');
Update Link
Delete Link
Reset Password : See Here &
See Here Too
Simply login to postgreSQL
psql -U postgres -W template1
-U = username
postgres is root
-W = ask for password
tempalte1 = default database
Create a database
-- Create the database from within postgresql
create database my_database_name
-- Connect to the database
\c my_database_name
-- Create the database without logging in
createdb -U postgres -W my_database_name
Add a table
Insert a record
Delete , update etc
All the above from 3 to 5 are like in MySQL
For resetting postgres forgotten password this link is a good reference.
postgresql is a completely different system than mysql; so do not assume things will be like mysql. They are completely different animals entirely; some of your SQL statements might not work, especially if you are using a MySQL proprietary command.
To login to postgresql, use the psql command shell
CREATE DATABASE
CREATE TABLE
INSERT
For all other basic SQL commands, consider going through the tutorial
User access control is something more fine grained and detailed in postgresql. There are users and roles. A user is simply a role that has the ability to login (like MySQL), but in postgresql you can have roles (an account) that cannot login.
What access a role has is defined in pg_hba.conf. This file defines if a role can login at all, by what means are they authenticated, from where they can login and what database they have access to.
ALTER USER is used to reset credentials.
The "root user" for postgresql is typically postgres; and this is a system user that is created during the install process. For Windows, the binary installer will ask if you want to launch the service as this user as well.
Please take a look at this PostgreSQL error 'Could not connect to server: No such file or directory'
Try to install postgresApp, this solved my problem which was the same of yours.
I have exported a full backup of a database with HeidiSQL 7.
Now when importing it via PHPMyAdmin, I noticed that I MUST select the database information_schema, because that's how the DB is exported (Or this is how HeidiSQL 7 exports databases as objects to an SQL file?).
However, that is a problem because when I import (the exported file) with HeidiSQL 7 (instead of PHPMyAdmin), while selecting the information_schema database, and clicking on Import SQL file (from the tools menu), it says that access is denied for the root user.
In PHPMyAdmin, the option to import is not available when selecting the database information_schema.
How do I import my full database dump? (This is how I exported it: HeidiSQL > export database objects to SQL file)
Edit:
I tried it with the command line, but without luck:
C:\Programs\XAMPP\mysql\bin>mysql --verbose --user=root Information_schema < DT.
sql
--------------
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */
--------------
--------------
/*!40101 SET NAMES utf8 */
--------------
--------------
/*!40014 SET FOREIGN_KEY_CHECKS=0 */
--------------
--------------
/*!40000 ALTER TABLE `CHARACTER_SETS` DISABLE KEYS */
--------------
ERROR 1044 (42000) at line 13: Access denied for user 'root'#'localhost' to data
base 'information_schema'
C:\Programs\XAMPP\mysql\bin>
This is a snippet of the SQL file:
http://pastebin.com/6hwhK2CJ
Note: The password for my root user is blank.
Maybe another solution for my problem:
How do I import only the database I want, from the SQL file? For example a database with the name "Employees"? Because that SQL file should contain a few databases.
Edit2:
(answer to first comment)
I downloaded MySQL Workbench, setup the connection...
03:23:08 Restoring C:\Files\DB.sql
Running: mysql.exe --defaults-extra-file="c:\files\temp\tmplnjwd6.cnf" --host=localhost --user=root --port=3306 --default-character-set=utf8 --comments < "C:\\Files\\DB.sql"
ERROR 1046 (3D000) at line 13: No database selected
Operation failed with exitcode 1
03:23:08 Import of C:\Files\DB.sql has finished with 1 errors
INFORMATION_SCHEMA is a pseudo, read-only database (in fact, it is an "ANSI standard set of read-only views").
You need to remove all dump data related to this pseudo database, as there is absolutely no way to import it.
Notepad++ is able to easily handle a 9 MB file, and also provides nice syntax highlighting.
This question already has answers here:
How do I rename a MySQL database (change schema name)?
(46 answers)
Closed 11 days ago.
I am using MySQL 5.0.
I have created a database named accounts, but now I want to change the database name to FinanceAccounts.
How can I change the database name in MySQL 5.0?
I think there is only one way (besides renaming directory in the MySQL datadir which will fail for InnoDB tables):
create new database (with new name)
make dump of old database
import dumped data into new database
delete old database
To create the new DB:
mysql> CREATE DATABASE new_database;
To create the dump of the old DB:
mysqldump -u "your_username" -p --lock-tables old_database > old_database_dump.sql
To import dumped data into the new DB:
mysql -u "your username" -p new_database < old_database_dump.sql
To delete the old DB:
mysql> DROP DATABASE old_database;
Bear in mind that your permissions on the old DB will need to be deleted as well. See here for more info:
Revoke all privileges for all users on a MySQL DB
MySQL 5.1.7 to MySQL 5.1.22 had a RENAME {DATABASE | SCHEMA} db_name TO new_db_name; command but this one has been removed in MySQL 5.1.23 for being too dangerous.
The best way is probably to rename each of the tables inside the database to the new name. For example:
Update: There are two steps here
Create a new blank database as you want say "new accounts"
CREATE DATABASE newaccounts;
Migrate each table one-by-one
RENAME TABLE accounts.tablename TO newaccounts.tablename;
See
http://dev.mysql.com/doc/refman/5.0/en/rename-table.html
for more information.
MySQL kinda sucks for this. The only solid reliable solution is to use phpMyAdmin.
Login > click Scheme > click "Operations" > find "Rename database to:" > write NewName > click "Go."
As simple as that. All permissions are carried over.
here , I rename mydb database to ecommerce, you follow this steps, but usin phpmyadmin is to easy
CREATE DATABASE `ecommerce` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
RENAME TABLE `mydb`.`Articles` TO `ecommerce`.`Articles` ;
RENAME TABLE `mydb`.`Categories` TO `ecommerce`.`Categories` ;
RENAME TABLE `mydb`.`Utilisateurs` TO `ecommerce`.`Utilisateurs` ;
ALTER TABLE `Articles` ADD CONSTRAINT fk_Articles_Categories FOREIGN KEY ( Categorie_id ) REFERENCES Categories( id ) ON DELETE NO ACTION ON UPDATE NO ACTION ;
DROP DATABASE `mydb` ;
To Rename MySQL Database name follow the following steps:
1) Click the database name
2) Click at Operations from the top menu
3) Type new database name Under Rename database to: