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

Find out If MySQL Is Running On Linux Or Not

# mysqladmin -u root -p status  

Output (if yes):

"Enter password: Uptime: 4 Threads: 1 Questions: 62 Slow queries: 0 Opens: 51 Flush tables: 1 Open tables: 45 Queries per second avg: 15.500"

Output (Else)

"mysqladmin: connect to server at 'localhost' failed error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists! "
Under Debian Linux you can type following command to find out if MySQL server is running or not 

# /etc/init.d/mysql status

If you are using RedHat of Fedora then you can use following script”

# service mysqld status
OR
# /etc/init.d/mysqld status

Reference :
Cyberciti


List Running Service On Linux

List running services using service command on a CentOS/RHEL 6.x or older

  • service –status-all
  • service –status-all | more
  • service –status-all | grep ntpd
  • service –status-all | less

PRINT THE STATUS OF ANY SERVICE

service httpd status

LIST ALL KNOWN SERVICES (CONFIGURED VIA SYSV)

chkconfig –list s

LIST SERVICE AND THEIR OPEN PORTS

netstat -tulpn

  • TURN ON / OFF SERVICE
  • ntsysv
  • chkconfig service off
  • chkconfig service on
  • chkconfig httpd off
  • chkconfig ntpd on

Reference
cyberciti

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]