I can’t seem to login to my tutorial database development environment:
Ayman$ mysql -u blog -p blog_development
Enter password:
ERROR 1049 (42000): Unknown database 'blog_development'
I can login to the database fine without the blog_development portion:
Ayman$ mysql -u blog -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1858
Not sure what gives as I granted all access:
mysql> GRANT ALL PRIVILEGES ON blog_development.*
-> TO 'blog'@'localhost'
-> IDENTIFIED BY 'newpassword';
Query OK, 0 rows affected (0.01 sec)
mysql> SHOW GRANTS FOR 'blog'@'localhost'
-> ;
+----------------------------------------------------------------------------------------- --------------------+
| Grants for blog@localhost |
+----------------------------------------------------------------------------------------- --------------------+
| GRANT USAGE ON *.* TO 'blog'@'localhost' IDENTIFIED BY PASSWORD '*FE4F2D624C07AAEBB979DA5C980D0250C37D8F63' |
| GRANT ALL PRIVILEGES ON `blog`.* TO 'blog'@'localhost' |
| GRANT ALL PRIVILEGES ON `blog_development`.* TO 'blog'@'localhost' |
+----------------------------------------------------------------------------------------- --------------------+
3 rows in set (0.00 sec)
Anybody have a clue what to try? Thanks! Also, side note- is it weird I have multiple root users?:
mysql> select User from mysql.user;
+------+
| User |
+------+
| root |
| root |
| |
| root |
| |
| blog |
| root |
+------+
7 rows in set (0.00 sec)
Edit: for those asking- I created the database blog with the CREATE DATABASE command in MySql. Here are my active databases:
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| blog |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
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'
BenMorel
33.5k49 gold badges174 silver badges310 bronze badges
asked Oct 30, 2013 at 9:44
5
If dump file contains:
CREATE DATABASE mydatabasename;
USE mydatabasename;
You may just use in CLI:
mysql -uroot –pmypassword < mydatabase.sql
It works.
answered Mar 24, 2016 at 17:02
DobpbiuDobpbiu
4814 silver badges4 bronze badges
2
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;
answered Oct 30, 2013 at 10:02
zessxzessx
67.5k28 gold badges135 silver badges157 bronze badges
1
Open the sql file and comment out the line that tries to create the existing database and remove USE mydatabasename
and try again.
answered Oct 30, 2013 at 10:05
Sathish DSathish D
4,83629 silver badges44 bronze badges
0
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;
answered Oct 11, 2016 at 8:20
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;
answered Jan 31, 2017 at 2:55
molavecmolavec
8,6311 gold badge26 silver badges21 bronze badges
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
answered Oct 19, 2020 at 8:05
Nabeel ShaikhNabeel Shaikh
1,1391 gold badge13 silver badges27 bronze badges
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:Usersusernamedesktop"
.
Thank you.
joanolo
5,7581 gold badge26 silver badges35 bronze badges
answered Aug 1, 2017 at 19:08
jhamezzz1315jhamezzz1315
231 gold badge4 silver badges10 bronze badges
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
answered Dec 9, 2019 at 17:19
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
answered Jan 23, 2020 at 15:42
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).
Rohan Shah
8491 gold badge8 silver badges26 bronze badges
answered Feb 20, 2020 at 11:30
1
mysql -uroot -psecret mysql < mydatabase.sql
answered May 29, 2020 at 14:40
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
answered May 26, 2021 at 10:18
It works by creating database and than typing command as :
C:Program FilesMySQLMySQL Server 8.0bin>mysql -u root -p -D cricket < C:Usershabib_s9ayvflDesktopsqlfile.sql
answered Aug 12, 2021 at 10:14
Create database:
CREATE DATABASE mydatabasename;
USE mydatabasename;
use this one:
mysql -u root -p ‘mydatabasename'< ‘/tmp/db_dump.sql’
answered Feb 11, 2022 at 10:33
Its very simple: Use mysql -u root -p mysql
answered Mar 25, 2022 at 9:58
sreesree
511 silver badge3 bronze badges
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
answered Apr 30, 2022 at 8:12
LIU YUELIU YUE
1,45511 silver badges18 bronze badges
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;
answered Jun 20, 2022 at 12:05
alexlzalexlz
6081 gold badge9 silver badges24 bronze badges
when u import database from workbench or other method ,should be give same name as your dump to avoid this kind of error
answered Jul 24, 2020 at 11:56
1
In fact, I made a very serious mistake, and this mistake can only be reported for two reasons.
Reason 1: There is an extra space after your account password, which means you have the wrong database.
Fix: If it is a login password, report this error, as shown in the figure below:
It would be possible to have an extra space between p and 123, and then you would remove the space in between. You put p and 123 together and you type in p123
Reason 2: Your syntax is wrong, because use can only be followed by the database name, never the table name. An incorrect or incorrect table name will report the following error.
Solution: Double check your database to see if it has TB_EMP6.
Check your table again to see if it is your table name.
The name of the table is confused with the database name.
Summary is to confirm the database name is not exist, there are no spelling mistakes, if not again to see your grammar is not wrong.
This is better to locate your problem, in fact, to put it bluntly this is I made a stupid mistake, but also eat a catty gain a wisdom.
Hope to help you, welcome to leave a message to exchange ~
Read More:
Я не могу войти в мою среду разработки учебной базы данных:
Ayman$ mysql -u blog -p blog_development
Enter password:
ERROR 1049 (42000): Unknown database 'blog_development'
Я могу войти в базу данных отлично без части blog_development:
Ayman$ mysql -u blog -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1858
Не уверен, что дает, когда я предоставил весь доступ:
mysql> GRANT ALL PRIVILEGES ON blog_development.*
-> TO 'blog'@'localhost'
-> IDENTIFIED BY 'newpassword';
Query OK, 0 rows affected (0.01 sec)
mysql> SHOW GRANTS FOR 'blog'@'localhost'
-> ;
+----------------------------------------------------------------------------------------- --------------------+
| Grants for [email protected] |
+----------------------------------------------------------------------------------------- --------------------+
| GRANT USAGE ON *.* TO 'blog'@'localhost' IDENTIFIED BY PASSWORD '*FE4F2D624C07AAEBB979DA5C980D0250C37D8F63' |
| GRANT ALL PRIVILEGES ON `blog`.* TO 'blog'@'localhost' |
| GRANT ALL PRIVILEGES ON `blog_development`.* TO 'blog'@'localhost' |
+----------------------------------------------------------------------------------------- --------------------+
3 rows in set (0.00 sec)
Кто-нибудь знает, что попробовать? Благодарю! Кроме того, боковое примечание — это странно, у меня есть несколько пользователей root?:
mysql> select User from mysql.user;
+------+
| User |
+------+
| root |
| root |
| |
| root |
| |
| blog |
| root |
+------+
7 rows in set (0.00 sec)
Изменить: для тех, кто спрашивает: я создал блог базы данных с командой CREATE DATABASE в MySql. Вот мои активные базы данных:
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| blog |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
This document (7009762) is provided subject to the disclaimer at the end of this document.
Environment
SUSE Linux Enterprise Server 10 Service Pack 1
SUSE Linux Enterprise Server 10 Service Pack 2
SUSE Linux Enterprise Server 10 Service Pack 3
SUSE Linux Enterprise Server 10 Service Pack 4
SUSE Linux Enterprise Server 11 Service Pack 1
SUSE Linux Enterprise Server 11 Service Pack 2
Situation
ERROR 1049 (42000): Unknown database ‘mysql’ when trying to access mysql via this command:
this command will access the default ‘mysql’ database, and needs to be done prior to setting or resetting the root users’ MySQL password.
Resolution
Depending on how MySQL was installed, it is possible that the default MySQL database was NOT created.
This may be checked by looking in /var/lib/mysql for a mysql subfolder (i.e. /var/lib/mysql/mysql ). If the path does NOT contain a mysql subfolder, it needs to be created by completing the following steps:
rcmysql stop pkill mysql (NOTE: wait until notification is given that mysqld ended, then hit <ENTER>) /usr/bin/mysql_install_db
Now that the above steps have been run, check and make sure that the database was created:
cd /var/lib/mysql ls -al | grep mysql
In the listing output there should now be a folder called mysql. Finally, the correct owner and group need to be set on the mysql folder.
Restart the mysql service in safe mode again and attempt the initial command again:
Disclaimer
This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented «AS IS» WITHOUT WARRANTY OF ANY KIND.
- Document ID:7009762
- Creation Date:
17-Nov-2011 - Modified Date:12-Aug-2022
-
- SUSE Linux Enterprise Server
< Back to Support Search
For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com
Mysqldump is a tool frequently used in creating a backup of a mariadb or mysql database. To use this tool is pretty straight forward, just run below command:
$ mysqldump -u root -p mydatabasename > mydatabasename.sql
The above command is fine, and we can always restore the data from the sql file into a database provided we have the database already in place, using below command:
$ mysql -u root -p mydatabasename < mydatabasename.sql
A problem appears when we are transferring the sql file to another server which does not have the database already created. If we try to import the sql file, without the database already existed, we will get below error:
ERROR 1049 (42000): Unknown database mydatabasename
We can prevent this by adding an option to our mysqldump command. The option is «—databases» or in short «-B». To test it out, we can use below commands (dump the db, drop the db, and import back the db from the sql file):
$ mysqldump -u root -p —databases mydatabasename > mydatabasename.sql
$ mysqladmin -u root -p drop mydatabasename
$ mysql -u root -p < mydatabasename.sql
This time, you would not get the above error, since the «—databases» option will add «CREATE DATABASE» query into the sql file, and that query will create the database if the database is not already exist.
There are a lot of developers who claim that visual editors (like in this case to import the database phpmyadmin) are not as trustworthy as the command line. Besides it isn’t fancy, however there are a lot of reasons why some people prefer the command line instead of an UI.
One of the most known reasons, in this case is the task of import a database, because as everybody knows there’s a limitation with the filesize of a database with phpmyadmin (Max: 2,048KiB with the default configuration of xampp). This in turn, isn’t a big limitation as you can increase the allowed filesize of the database however it will take time to configure it and it won’t be so fast as with the command line (at less for people with a database of more than 100MB).
In this article you will learn how to import a mysql database with the command prompt in XAMPP for Windows.
1. Locate the mysql executable
The mysql executable is a simple SQL shell with input line editing capabilities. It supports interactive and noninteractive use. When used interactively, query results are presented in an ASCII-table format. When used noninteractively (for example, as a filter), the result is presented in tab-separated format. The output format can be changed using command options.
For our task, that is importing the database with the command line, this will be the required tool, therefore the first you need to do is to locate the executable of mysql in your xampp distribution. Open the xampp folder and search for the executable inside the mysql/bin
folder, in this example the executable will be located in the E:Programsxamppmysqlbin
folder:
Copy the path in the clipboard as you will need it in the next step.
2. Import the database with the command prompt
Using mysql from the command line interface is very easy. For example, to import a database we just need to execute the following command with the following arguments:
mysql -u {DATABASE_USERNAME} -p {DATABASE_NAME} < "path/to/file/database-to-import.sql"
That with some real values, should look like (importing the ourcodeworld.sql
database located in the desktop into the ourcodeworld
database):
mysql -u root -p ourcodeworld < "C:UserssdkcaDesktopourcodeworld.sql"
After the execution of the commands with the required values, the console will prompt for the password (that you should let empty in case there isn’t any and just press Enter) and will start importing the database. It seems pretty easy, however you may probably don’t know from where you need to execute the previous command, isn’t ? With windows there are 2 ways to do it:
A. With the entire executable path
In this way, you wont need to switch from path with the command prompt, therefore you can execute the command from wherever you are with the console (even with a new command prompt window). From the example command, replace mysql with the absolute path to the executable and you’re ready to go:
E:Programsxamppmysqlbinmysql.exe -u root -p ourcodeworld < "C:UserssdkcaDesktopourcodeworld.sql"
In the command prompt, the execution of the previous steps will show as result:
B. Changing of directory
The other way is simple too, you only need to change from directory with the command prompt to the path where the mysql executable is located (step 1), in this case mysql/bin
:
cd E:Programsxamppmysqlbin
And then execute the command again (replace mysql
with mysql.exe
if the command isn’t recognized):
mysql -u root -p ourcodeworld < "C:UserssdkcaDesktopourcodeworld.sql"
In the command prompt, the execution of the previous steps will show as result:
Note
In case that you get the ERROR 1049 (42000): Unknown database ‘your-database-name’ during the importation, go to phpmyadmin and create the database manually before importing it.
With any of the previous step, there should not be any kind of output if the database was succesfully imported, otherwise something went wrong.
Happy coding !
0 / 0 / 0 Регистрация: 03.12.2017 Сообщений: 18 |
|
1 |
|
MySQL 03.09.2018, 11:57. Показов 5828. Ответов 6
Дело вот в чем. Учу php, работаю с БД через phpMyAdmin.
__________________
0 |
Programming Эксперт 94731 / 64177 / 26122 Регистрация: 12.04.2006 Сообщений: 116,782 |
03.09.2018, 11:57 |
6 |
шКодер самоучка 2173 / 1880 / 912 Регистрация: 09.10.2013 Сообщений: 4,135 Записей в блоге: 7 |
|
03.09.2018, 12:45 |
2 |
«имя БД» Что, так БД и называется? Добавлено через 4 минуты
0 |
0 / 0 / 0 Регистрация: 03.12.2017 Сообщений: 18 |
|
03.09.2018, 12:50 [ТС] |
3 |
База данных подключена и работает, просто phpMyAdmin не создает почему то новую таблицу в уже существующей базе myshop, и пишет ошибку будтоэта БД неизвестна, хотя она есть в меню слева и работает при этом. Миниатюры
0 |
шКодер самоучка 2173 / 1880 / 912 Регистрация: 09.10.2013 Сообщений: 4,135 Записей в блоге: 7 |
|
03.09.2018, 14:17 |
4 |
_FraeRock_, попробуйте пересоздать БД
1 |
276 / 259 / 185 Регистрация: 15.08.2017 Сообщений: 1,483 |
|
03.09.2018, 17:44 |
5 |
возможно закончилось место на разделе диска
0 |
618 / 216 / 51 Регистрация: 22.11.2010 Сообщений: 1,776 Записей в блоге: 3 |
|
03.09.2018, 18:50 |
6 |
Очевидно неправильное написание наименования экземпляра БД, но без кода сложнее разгадать.
0 |
0 / 0 / 0 Регистрация: 03.12.2017 Сообщений: 18 |
|
05.09.2018, 12:43 [ТС] |
7 |
Спасибо всем, но помогло действительно пересоздание всей БД
0 |
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
05.09.2018, 12:43 |
7 |