start command
sudo service mysqld start
stop order
sudo service mysqld stop
Check if the MySQL service is running:
sudo systemctl status mysql
Use the command to check whether it is started
ps -ef|grep mysqld
Use the command to connect
mysql -u -p passwd
Enter the password according to the prompt to enter the mysql command line.
View the number of databases:
show databases;
View the number of a database table :
SELECT count(TABLE_NAME) FROM information_schema.TABLES WHERE TABLE_SCHEMA='database name';
View the specified database size:
SELECT sum(DATA_LENGTH)+sum(INDEX_LENGTH) FROM information_schema.TABLES where TABLE_SCHEMA='数据库名';
The result obtained is in bytes
New database command:
create database database name;
Backup database command :
mysqldump -u root -p database name> 2015.9.21.sql;
Import a large SQL file command to the database:
source + file path/file name
In the MySQL database:
Query all column names of a table in a database
SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'db_name' AND TABLE_NAME = 'tb_name';
Query all column names of a table in a database and connect them with commas
SELECT GROUP_CONCAT(COLUMN_NAME SEPARATOR ",") FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'db_name' AND TABLE_NAME = 'tb_name';
Note: only need to replace db_name (database name) and tb_name (table name)