Detailed explanation of common operation instructions of Linux terminal MySQL

  • 2021-10-13 08:56:58
  • OfStack

Services:


# chkconfig --list     List all system services 
# chkconfig --list | grep on    List all started system services 
# chkconfig --list mysqld 
# whereis mysql  View the file installation path 
# which mysql    Query the path of the running file ( Folder address )
usr/bin/mysql  Refers to: mysql Running path of 
var/lib/mysql  Refers to: mysql Storage path of database files 
usr/lib/mysql  Refers to: mysql Installation path of 

Add environment variables:


# vi /etc/profile
# export MYSQL_HOME=/usr/local/mysql
# export PATH=$PATH:$MYSQL_HOME/bin

1. Database directives:


# service mysqld start   Start MySQL
# service mysqld restart  Restart MySQL
# service mysqld stop    Stop MySQL

2. Enter the MySQL form action


# -u root -p /mysql -h localhost -u root -p DatabaseName;   Enter MySQL
 MySQL> show databases;       List databases 
 MySQL> create database XXX;    Create a database XXX
 MySQL> use databaseName;      Working with a database databaseName
 MySQL> show tables;        List forms 
MySQL> create table mytablename (ID int auto_increment not null primary key,usename varchar(20),password varchar(64),sex varchar(10),address varchar(20));  Create a form 
MySQL> drop table mytablename ;          Delete a form 
MySQL> drop database databasename;        Delete a database 

3. Add, delete and check


MySQL> insert into mytablename values('','zhangsan','123456','fomale','guiyanag');  Insert 
MySQL> select * from mytablename ;          Find validation results 
MySQL> select * from mytablename where ID = '1';  Accurate search 
MySQL> update mytablename set address = 'shanghai' where username = 'zhangsan';  Modify zhangsan Adj. address For shanghai
MySQL> delete from mytablename where ID = '1';    Delete a record 

Add universal users


grant select On database.* to username@localhost identity by 'password'

User name user_1 password is 123456

This user can log in from any PC to operate on the database


MySQL> grant select,insert update,delete on *.* to user_1@"%" identity by "123456";

Create a user who can operate the database only locally

User name user2 password is 123456


MySQL> grant select,insert update,delete on *.* to user_2@localhost identity by "123456";

Login database library


MySQL> -u user_1 -p -h IP Address ;

Summarize


Related articles: