ERROR 1046:No database selected
Firstly you need to tell MySQL which database you would like to use to create a table:
USE your_database_name;
If your database does not exist yet, you have to create one:
CREATE DATABASE your_database_name;
then tell MySQL that you want to use it:
USE your_database_name;
and then you can create a table.
Hope it will help you to solve this problem :)
Trying to insert data into SQL database. Error 1046 No Database Selected
There are two approaches to solve this:
- You run
cursor.execute('use my_database;')
- Or you adapt your SQL statements to specify the DB like:
cursor.execute('INSERT INTO my_database.info(Disease, NCBI Acc. Number, Length, Sequence ) VALUES(%s, %s, %s, %s)', row)
Note, with the later approach you need to adapt all sql statements
Add a css class with Html.RouteLink
Try this:
<%= Html.RouteLink("Default", "Default",null, new { @class="css_class"}) %>
ERROR 1046 (3D000) at line 1: No database selected
You can fix/simplify this in a couple of ways:
- By removing the separate USE statement.
- By removing the user credentials from the command line.
Reference the database name directly in the UPDATE statement:
sql="UPDATE wp_posts SET ${tmpdb}.post_content = replace(post_content, 'domain1', 'domain2');"
If you have version mysql >= 5.6.6, use mysql_config_editor
to put the login credentials into a .mylogin.cnf file. It'll save typing and the password will be encrypted.
e.g.
mysql_config_editor --login-path=root --user=root --host=localhost --password
Once set, your bash command would then be simpler (and safer)
tmpdb=yyyy
sql="UPDATE wp_posts SET ${tmpdb}.post_content = replace(post_content, 'domain1', 'domain2');"
mysql --login-path=root -e "$sql"
or, since the variable aren't really necessary here,
mysql --login-path=root -e "UPDATE wp_posts SET yyyy.post_content = replace(post_content, 'domain1', 'domain2');"
Error Code: 1046. No database selected Select the default DB to be used by double-clicking its name in the SCHEMAS list in the sidebar
If you call the SQL from Workbench then add
use ;
before the SQL.
If it's called from java check how you specify DB name in your connection URL
Related Topics
How to Select from Subquery Using Laravel Query Builder
Query With Left Join Not Returning Rows For Count of 0
Fastest Way to Perform Nested Bulk Inserts With Scope_Identity() Usage
Humanized or Natural Number Sorting of Mixed Word-And-Number Strings
Select/Group by - Segments of Time (10 Seconds, 30 Seconds, etc)
Does Foreign Key Improve Query Performance
Cumulative Sum Over a Set of Rows in MySQL
Search for a String in All Tables, Rows and Columns of a Db
Inner Join VS Natural Join VS Using Clause: Are There Any Advantages
How to Include a PHP Variable Inside a MySQL Statement
MySQL Delete from With Subquery as Condition
How to Generate a Range of Dates in SQL Server
Oracle SQL - How to Retrieve Highest 5 Values of a Column
How to Query a Tree Structure Table in MySQL in a Single Query, to Any Depth
Simulate Create Database If Not Exists For Postgresql