Common operation commands of MySQL in Linux system

Common operation commands of MySQL in Linux system

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 runs the file path (folder address)
usr/bin/mysql means: 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 databases
MySQL> create database XXX; Create database XXX

MySQL> use databaseName; Use database databaseName
MySQL> show tables; List tables

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 table
MySQL> drop table mytablename ; Delete table
MySQL> drop database databasename; Delete database

3. Add, delete, modify and check

MySQL> insert into mytablename values('','zhangsan','123456','fomale','guiyanag');

MySQL> select * from mytablename ; Find the verification result
MySQL> select * from mytablename where ID = '1'; Accurate search

MySQL> 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地址;

In addition, I list some commonly used commands for reference only:

Other MySQL database related operations are as follows

(1) Create a database TestDB mysql> create database TestDB;
(2) Set the TestDB database as the current default database mysql> use TestDB;
(3) Create the customers table in the TestDB database mysql> create table customers(userid int not null, username varchar(20) not null);
(4) Display the database listmysql> show databases;
(5) Display the tables in the database mysql> show tables;
(6) Delete the customers table mysql> drop table customers;
(7) Display the structure of the customers tablemysql> desc customers;
(8) Insert a record into the customers tablemysql> insert into customers(userid, username) values(1, 'hujiahui');
(9) Make the operation take effect immediately; mysql> commit;
(10) Query the records in customersmysql> select * from customers;
(11) Update data in the tablemysql> update customers set username='DennisHu' where userid=1;
(12) Delete records from the tablemysql> delete from customers;
(13) Grant the likui user the permission to access the database # grant select, insert, update, delete on *.* to likui@localhost indentified by "123456";

You may also be interested in:
  • Summary of Commonly Used MySQL Commands in Linux Operating System
  • How to install mysql using yum command in Linux Centos
  • Detailed explanation of LINUX restart MYSQL command
  • Introduction to commonly used MySQL commands in Linux environment

<<:  Complete steps for mounting a new data disk in CentOS7

>>:  JavaScript to achieve time range effect

Recommend

Example of using CSS filter to write mouse over effect

Use CSS filter to write mouse over effect <div...

Example of how to use CSS3 to layout elements around a center point

This article introduces an example of how CSS3 ca...

Two ways to use react in React html

Basic Use <!DOCTYPE html> <html lang=&qu...

How to handle token expiration in WeChat Mini Programs

Table of contents Conclusion first question Solut...

Example of stars for CSS rating effect

What? What star coat? Well, let’s look at the pic...

Simple analysis of EffectList in React

Table of contents EffectList Collection EffectLis...

Spring Boot layered packaging Docker image practice and analysis (recommended)

Table of contents 1. Prepare the springboot proje...

How to invert the implementation of a Bezier curve in CSS

First, let’s take a look at a CSS carousel animat...

A brief talk about the diff algorithm in Vue

Table of contents Overview Virtual Dom principle ...

Vue.js $refs usage case explanation

Despite props and events, sometimes you still nee...

Summary of Button's four Click response methods

Button is used quite a lot. Here I have sorted ou...

...