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

An article to master MySQL index query optimization skills

Preface This article summarizes some common MySQL...

Vue realizes the card flip effect

This article example shares the specific code of ...

Detailed explanation of small state management based on React Hooks

Table of contents Implementing state sharing base...

Basic learning and experience sharing of MySQL transactions

A transaction is a logical group of operations. E...

Introduction to the use of several special attribute tags in HTML

The following attributes are not very compatible w...

Detailed tutorial on setting password for MySQL free installation version

Method 1: Use the SET PASSWORD command MySQL -u r...

Detailed explanation of MySQL combined index and leftmost matching principle

Preface I have seen many articles about the leftm...

Example of how to deploy a Django project using Docker

It is also very simple to deploy Django projects ...

CSS+HTML to realize the top navigation bar function

Implementation of navigation bar, fixed top navig...

Detailed explanation of common usage of pseudo-classes before and after in CSS3

The before/after pseudo-class is equivalent to in...

Introduction to Docker Quick Deployment of SpringBoot Project

1. Install Docker First open the Linux environmen...

JavaScript Basics: Scope

Table of contents Scope Global Scope Function Sco...

Detailed explanation of Redis master-slave replication practice using Docker

Table of contents 1. Background 2. Operation step...

vue3+ts+EsLint+Prettier standard code implementation

Table of contents use Use of EsLint Add a profile...