Detailed explanation of common MySQL operation commands in Linux terminal

Detailed explanation of common MySQL operation commands in Linux terminal

Serve:

# 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 where the running file is located (folder address)
usr/bin/mysql refers to: the running path of mysql var/lib/mysql refers to: the storage path of mysql database files usr/lib/mysql refers to: the installation path of mysql

Add environment variables:

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

1. Database instructions:

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

2. Enter the MySQL form operation

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

3. Add, delete, modify and check

MySQL> insert into mytablename values('','zhangsan','123456','fomale','guiyanag'); InsertMySQL> select * from mytablename; Find verification resultsMySQL> select * from mytablename where ID = '1'; Accurate searchMySQL> update mytablename set address = 'shanghai' where username = 'zhangsan'; Change zhangsan's address to shanghai
MySQL> delete from mytablename where ID = '1'; Delete records

Add universal user

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

Username user_1 Password is 123456

You can log in as this user from any PC to operate the database

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

Create a user who can only operate the database on this machine

Username user_2 Password is 123456

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

Login database

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

Summarize

The above are the common operating instructions of MySQL in Linux terminal introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • MySQL database terminal - common operation command codes

<<:  Detailed explanation of EXT series file system formats in Linux

>>:  Implementing a web calculator based on JavaScript

Recommend

How to use Vue cache function

Table of contents Cache function in vue2 Transfor...

How to check PCIe version and speed in Linux

PCIE has four different specifications. Let’s tak...

...

Use CSS to create 3D photo wall effect

Use CSS to create a 3D photo wall. The specific c...

mysql5.6.zip format compressed version installation graphic tutorial

Preface: MySQL is a relational database managemen...

Detailed explanation of the process of using docker to build minio and java sdk

Table of contents 1minio is simple 2 Docker build...

Vue implements form validation function

This article mainly describes how to implement fo...

How to implement Linux automatic shutdown when the battery is low

Preface The electricity in my residence has been ...

Completely delete MySQL steps

Table of contents 1. Stop MySQL Server first 2. U...

Summary of React's way of creating components

Table of contents 1. Create components using func...

Explanation of the configuration and use of MySQL storage engine InnoDB

MyISAM and InnoDB are the most common storage eng...