Error 1046 No Database Selected, How to Resolve

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:

  1. You run cursor.execute('use my_database;')
  2. 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:

  1. By removing the separate USE statement.
  2. 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



Leave a reply



Submit