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

getdata table table data join mysql method

public function json_product_list($where, $order)...

Vue uses echarts to draw an organizational chart

Yesterday, I wrote a blog about the circular prog...

WeChat applet date and time component (year, month, day, hour, and minute)

This article example shares the specific code of ...

Analyze how uniapp dynamically obtains the interface domain name

background The interface domain name is not hard-...

The implementation process of ECharts multi-chart linkage function

When there is a lot of data to be displayed, the ...

How to call the interrupted system in Linux

Preface Slow system calls refer to system calls t...

How to set the border of a web page table

<br />Previously, we learned how to set cell...

Detailed explanation of how to customize the style of CSS scroll bars

This article introduces the CSS scrollbar selecto...

How to implement JavaScript output of Fibonacci sequence

Table of contents topic analyze Basic solution Ba...

Explanation of the configuration and use of MySQL storage engine InnoDB

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

Detailed tutorial for installing mysql5.7.21 under Windows system

MySQL Installer provides an easy-to-use, wizard-b...

CSS horizontal centering and limiting the maximum width

A CSS layout and style question: how to balance h...

Detailed explanation of custom events of Vue components

Table of contents Summarize <template> <...