How to fix the “#1046: No database selected” error in phpMyAdmin

  • Create the new database on your server, then write down the name.
  • Open your .sql file with a text editor
  • Insert the following line right before the first CREATE TABLE instruction in your .sql file: USE your_database_name_here;
  • Save your file, then import it in phpMyAdmin.

Reference :
wisercoder

MySQL List Command

version:
# mysql -V

Connect to the MySQL
# mysql -u root -p

If you haven’t already set up password for the MySQL root user, you can use the following command:
# mysql -u root

if you haven’t set up the MySQL root password yet , use the following command:
# mysql_secure_installation

To list all databases in MySQL, run the following command:
# mysql> show databases;

if you want to use a specific database and list all tables in it, , use the following command:
# mysql> use mysql;

To list the tables, you can use the command below:
# mysql> show tables

If you want to find out about the structure of a specific table you can use the DESCRIBE statement in MySQL:
# mysql> DESCRIBE user;

Reference :
Rosehosting

MySQL – Retrieve username & password

  • Stop the MySQL process.
  • Start the MySQL process with the –skip-grant-tables option.
  • Start the MySQL console client with the -u root option.
  • SELECT * FROM mysql.user;
  • UPDATE mysql.user SET Password=PASSWORD('[password]') WHERE User='[username]';

But DO NOT FORGET to

  • Stop the MySQL process
  • Start the MySQL Process normally (i.e. without the –skip-grant-tables option)

when you are finished. Otherwise, your database’s security could be compromised.

Reference :
Stackoverflow
TechRepublic
Digitalocean

“Connect failed: Access denied for user ‘root’@’localhost’ (using password: YES)” from php function

  • mysql -u root -p -h localhost
  • CREATE USER 'francesco'@'localhost' IDENTIFIED BY 'some_pass';
  • CREATE DATABASE shop;
  • GRANT ALL PRIVILEGES ON shop.* TO 'francesco'@'localhost';
  • quit;
  • mysql -u francesco -p -h localhost
  • source shop.sql;
  • $conn = new mysqli("localhost", "francesco", "some_pass", "shop");
  • Reference :

Reference :
Stackoverflow
Stackoverflow [error 1045]