I am trying to restore database from .sql file , i have created the database in phpmyadmin and also using the create if not exist command in the .sql file which i am restoring to the database and both names of database are same in phpmyadmin and .sql file which is"mydatabase".
Here is the command which i am using to restore database.
mysql -uroot -pmypassword mydatabase<mydatabase.sql;
When i execute the above command i am getting the following error, i have also given all the permission to the user upon this database.
ERROR 1049 (42000): Unknown database 'mydatabasename'
If dump file contains:
CREATE DATABASE mydatabasename;
USE mydatabasename;
You may just use in CLI:
mysql -uroot –pmypassword < mydatabase.sql
It works.
Whatever the name of your dump file, it's the content which does matter.
You need to check your mydatabase.sql and find this line :
USE mydatabasename;
This name does matter, and it's the one you must use in your command :
mysql -uroot -pmypassword mydatabasename<mydatabase.sql;
Two options for you :
Remove USE mydatabasename; in your dump, and keep using :
mysql -uroot -pmypassword mydatabase<mydatabase.sql;
Change your local database name to fit the one in your SQL dump, and use :
mysql -uroot -pmypassword mydatabasename<mydatabase.sql;
Open the sql file and comment out the line that tries to create the existing database and remove USE mydatabasename and try again.
You can also create a database named 'mydatabasename' and then try restoring it again.
Create a new database using MySQL CLI:
mysql -u[username] -p[password]
CREATE DATABASE mydatabasename;
Then try to restore your database:
mysql -u[username] -p[password] mydatabase<mydatabase.sql;
I solved because I have the same problem and I give you some clues:
1.- As #eggyal comments
mydatabase != mydatabasename
So, check your database name
2.- if in your file, you want create database, you can't set database that you not create yet:
mysql -uroot -pmypassword mydatabase<mydatabase.sql;
change it for:
mysql -uroot -pmypassword <mydatabase.sql;
Create database which gave error as Unknown database,
Login to mysql shell:
sudo mysql -u root -p
create database db_name;
Now try restoring database using .sql file, -p flag will ask for a sql user's password once command is executed.
sudo mysql -u root -p db_name < db_name.sql
La Chi's answer works for me.
You can view his/her answer in the comment of zessx answer in this page. But I initially have a problem with it if you also do just tweak his/her answer like this: mysql -h localhost -u root -p -D mydatabase < mydatabase.sql.
Also I would suggest that in the mydatabase.sql portion you include the direct location of it in your computer like "C:\Users\username\desktop".
Thank you.
If initially typed the name of the database incorrectly. Then did a Php artisan migrate .You will then receive an error message .Later even if fixed the name of the databese you need to turn off the server and restart server
I had the same issue, i run this command on command line and just like you i had added the ';' at the end. Removing it solved the issue.
Instead of this
mysql -uroot -pmypassword mydatabase<mydatabase.sql;
try this
mysql -uroot -pmypassword mydatabase<mydatabase.sql
I found these lines in one of the .sql files
"To connect with a manager that does not use port 3306, you must specify the port number:
$mysqli = new mysqli('127.0.0.0.1','user','password','database','3307');
or, in procedural terms:
$mysqli = mysqli_connect('127.0.0.0.1','user','password','database','3307');"
It resolved the error for me . So i will suggest must use port number while making connection to server to resolve the error 1049(unknown database).
mysql -uroot -psecret mysql < mydatabase.sql
I meet your issue. This is how to solve it
Check your DB name correct and exist in MySQL
Check if your IP and port is correct
It works by creating database and than typing command as :
C:\Program Files\MySQL\MySQL Server 8.0\bin>mysql -u root -p -D cricket < C:\Users\habib_s9ayvfl\Desktop\sqlfile.sql
Create database:
CREATE DATABASE mydatabasename;
USE mydatabasename;
use this one:
mysql -u root -p 'mydatabasename'< '/tmp/db_dump.sql'
Its very simple: Use mysql -u root -p mysql
first, you need to check the folder /var/lib/mysql for mydatabasename (depend on how you installed mysql, but default folder is this one),
please check the folder exists or not and its owner should be mysql:mysql, and of course the folder permission should be rw to mysql;
second, possibly because of you made changes to /etc/my.cnf, for example in my case, we created a database TEST_DB in uppercase, and then someone added lower_case_table_names=1 restriction in my.cnf, it caused the Unknown database error because mysql will transalte TEST_DB to lowercase test_db even when i key in select from TEST_DB, so it'll never find TEST_DB, simply comment out and restart mysql service solved my issue
You can also try
> mysql mysql
and you will connect to MySQL database from which you can create your own schema.
mysql> CREATE DATABASE mydb; USE mydb;
when u import database from workbench or other method ,should be give same name as your dump to avoid this kind of error
I am able to login with root - "No password", But i can't change password. I checked many links , everybody saying to run update query on user table , but i even can't find user table in phpmyadmin.
Error I am getting is :
$ /usr/local/mysql/bin/mysqladmin -u root -p password
Enter password:
New password:
Confirm new password:
/usr/local/mysql/bin/mysqladmin: Can't turn off logging; error: 'Access denied; you need (at least one of) the SUPER privilege(s) for this operation'
Any help will be highly useful
PHP My ADMIN (Screenshot): http://awesomescreenshot.com/021cxa0fb
Error: http://i47.tinypic.com/1j1b0m.png
Additional screenshot: http://i48.tinypic.com/w9vbtl.png
Additional screenshot 2: http://i48.tinypic.com/4rymps.png
it seems to me, that you use phpmyadmin to look for the table. if so, you won't see all tables. you have to log in to mysql as root with the "mysql" command in the terminal:
$ mysql -u root
then you can run the "update user..."-command (you don't have to see the table containing the user informations)
another idea: when you use the -p in the command line, you are not allowed to write the password next to it (it will ask you later on). if you write something after -p it will think that this is the database name...
From the additional information you have posted in comments it appears that your MySQL root user no longer has root privileges on your system. After performing a quick search looking for mysql reset root privileges I found this blog posting that appears to give detailed instructions on how to restore root privileges to your root account.
BEWARE, I have not tried these steps and they are from 2009 and it's possible that MySQL may have changed internally from when these instructions were created. However, that being said, the comments on the posting are positive (of course, the comments could be fake).
My recommendation is to backup the directory (or directories) containing all of your MySQL data and then trying these steps EXACTLY as they are laid out.
Looking more closely at these instructions they appear valid to me. I noticed that they involve taking down the MySQL daemon, restarting MySQL with an option that turns off all table security and then executing updates to add rights back to the root user. I now recommend giving these steps a try.
To set the root's password:
/usr/bin/mysqladmin -root password 'new-password'
try to know if mysql daemon is up:
/usr/bin/mysqladmin -u root -p ping
if not alive try :
/etc/init.d/mysql start
& verify that mcrypt package is installed.
I solved the Problem , Thanks for all.I reinstalled the mysql server as per following guide , the problem was I updated password directly to the mysql.user table with update query , its wrong , since the password should be stored as encrypted in mysql.user table , if we updating it directly through query then it will be a string.
Excellant guide : http://blog.mclaughlinsoftware.com/2011/02/10/mac-os-x-mysql-install/
Thanks again for everybody :)
I am trying to learn PHP and MySQL and while I reached a chapter on MySQL I was asked to create a database using this command:
CREATE DATABASE publications;
After I typed it in the mysql console I got this error:
ERROR 1044(42000):Access denied for user ''#localhost' to database 'root'
I am already logged in to my administrator account so I think the privileges should't be a problem.I have installed with the XAMPP package.
How can this be solved?
It could be possible that you upgraded your version of EasyPHP or you did something to disable the root password. If that is the case, you should try reestablishing a password for root. Had the same problem and that's how I solved it.
Go to http://localhost/xampp/ and set the appropriate passwords (in Security tab). If you use mysql client program, make sure you call it with appropriate credentials: mysql -u <username> -p <password>. Username will mostly be root until you create some new accounts.
Then I suggest you use phpMyAdmin for experimenting with MySQL (it should be at http://localhost/phpmyadmin/ )
This is getting a little confused - let me try to answer this.
Mysqladmin is a command line client for administering your mysql database system - you normally don't need to run it once you have mysql working. The shell command line interface to the mysql server is mysql. (If you don't know how to run a shell command line, that's another problem. Also, if you're on Windows, say so, since that has its own challenges.) The arguments are:
mysql -u username -ppassword databasename
if you are running this command on the same server as mysql. Note the lack of space after the -p - that is important.
So, type the above line to invoke the command line interface to mysql. Then you can type your mysql commands. Things like show tables, desc tablename, etc., will work. That is they will work unless you have an authentication problem. But you will know you have an authentication problem because when you tried to run mysql as above, it will fail with some error, like "Access denied for user 'abc'#'localhost' (using password: YES)". This is a nice descriptive error message that points you exactly where the problem is.
Does that help?
You can go back to using xampp or anything else once you've made sure that you know the right parameters by checking with the command line. (Always check with the command line when strangeness happens - it's so much easier than trying to debug through other interfaces.)
Im trying to create my own database with MySQL Workbench and run some queries on it. I have MySQL server 5.1 running and can enter queries in the command line tool to ask for version number and such.
But how do I get the server to host the database that I created in Workbench? When I enter "use MijnDatabase" or "-u root#localhost -p MijnDatabase" it says the database cannot be found. This makes sense, "MijnDatabase" the database file name and it's not connected to the server in any way (also tried with "mydb" wich is the db name I see inside Workbench).
Anyway I'm missing the link between MySQL server and hosting an actual database file.
When you create a database use only lower case letters and use underscore to separate words:
create database my_database;
use my_database;
show tables;
etc...
To connect to your database use:
mysql -u root -p
enter your password then
use my_database;
show tables;
etc...
I have not used MySQL Workbench but the command line and phpMyAdmin. I suggest you start using the command line to learn a little bit MySQL, then use a GUI tool. However the command line is your best teacher.
Have a look in the reference doc: http://dev.mysql.com/doc/refman/5.1/en/create-database.html
. Lean how to create a user and grant him permission on the database.
I have a local MYSQL DB running under WAMP that I need to move up to my production DB server. New to MySQL and need to know the best way to get this DB moved up.
you can run this on your current server:
mysqldump -u user -p database_name > dump.txt
and then do this on your new server:
mysql -u user -p database_name < dump.txt
Replace "user" with your username and "database_name" with a name of your database. You'll be prompted for a password in both cases
Note that second command will replace old tables in your new database
Open up your database in phpMyAdmin and then select Export from the menu. Scroll down and select the Save as file checkbox and then press Go.
Now open up the database in phpMyAdmin on the production server (Note: you will need to create the database first) and then select Import from the menu. Browser to the file you saved and press Go.
If everything goes well you should now have a mirror image of your database on the production server! :)
Do you have phpmyadmin? (If you're not sure, type "http://localhost/phpmyadmin"). If you do, go to "Export on your local computer, and then upload that file on the "Import" section of the remote server. This is the absolute easiest way, and 90% of hosts have phpmyadmin installed.
If you don't, use the command line method suggested by ZeppLock.