Summary of Commonly Used MySQL Commands in Linux Operating System

Summary of Commonly Used MySQL Commands in Linux Operating System

Here are some common MySQL commands for you:

 -- Start the database service myslqd start;
-- Enter MySQL -u root -p/mysql -h localhost -u root -p DatabaseName;
-- List database show database;
--Create database create database XXXX;
--Select databaseuse DatabaseName;
--show table;
-- Display the properties of the table show columns from tablename;
--Create database source filename.txt;
--Add a field alter table tablename add column filename datatype;
-- Add multiple fields alter table tablename add column filename1 datatype,add column filename2 datatype;
-- Add a new user grant all On *.* to user@localhost identity by "password";
--Query time select now();
--Query user select user();
--Query the database version select version();
--Query the currently used database select database();
-- Delete the student data in the student_course database: rm -f student_cource/student.*
--Backup database (backup database Apple1)
MySQLdump -u root -p Apple1>C:\Apple1.txt
--Backup table (backup the mytable table in database Apple1)
MySQLdump -u root -p mytable>C:\Apple.txt
-- Create a temporary table (mytable)
create temporary table mytable(id int,address varchar(20),name varchar(20));
-- Before creating a table, first determine whether the table exists in the system. create table if not exists mytable(......);
-- Copy the table structure from the existing table1 to table2
create table table2 select * from table1 where 1<>1;
-- Copy table create table table2 select * from table1;
-- Rename the table name alter table table1 rename as table2;
-- Modify the data type of the column alter table table1 modify ID int unsigned;--Change the type of column ID to int unsigned
alter table table1 change ID SID int unsigned; --Rename column ID to SID and change the type to int unsigned
-- Create index alter table table1 add index Ind_id (ID);
create index ind_ID on tablename (ID);
create unique index ind_id on tablename(ID);
-- Delete index drop index ind_id On table1;
alter table table1 drop index ind_ID;
--Join query characters and multiple columns'
select concat(ID,':',name,'=') from table1
-----------------------The second piece------------------------------------
--Show databaseshow database;
--Show tables in the database show tables;
--Display the data table structure describe tablename;
--Display table records select * from tablename;
--Query users who can operate MySQL select * from user;
--Create databasecreate database databasename
--For example↓
MySQL> create database AA;
---Create table user AA;
mysql> create table table1(ID int auto_increment not null primary key,name char(6),sex char(6),birthday date)
 ---Insert several recordsMySQL> insert into AA values('','张三','男','1971-10-01');
 MySQL> insert into AA values('','刘佳佳','女','1978-10-01');
 --Verify the resultMySQL> select * from AA;
--Change Zhang San's birthday to 1971-01-10
MySQL> update AA set birthday = '1971-01-10' where ID = '1'; 
--Delete recordsMySQL> delete from AA where ID = '1';
--Delete table and librarymysql> drop table tablename;
MySQL> drop database databasename;
--Add universal user-- Format: grant select On database.* to username@localhost identity by 'password'
Username user_1 Password is 123456
--You can log in to this user from any PC and do whatever you want with the databaseMySQL> grant select,insert update,delete on *.* to user_1@"%" identity by "123456";
--Create a user who can only operate the database on this machine. The username is user_2 and the password is 123456
MySQL> grant select,insert update,delete on *.* to user_2@localhost identity by "123456";
--Log in to the database MySQL> -u user_1 -p -h IP address;

The above is a summary of the common commands for operating MySQL on the Linux operating system. I hope it will be helpful to you. If you have any questions, please leave me a message and I 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:
  • Common operation commands of MySQL in Linux 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

<<:  Implementation steps for setting up the React+Ant Design development environment

>>:  Example of how to deploy a Django project using Docker

Recommend

Detailed explanation of Socket (TCP) bind from Linux source code

Table of contents 1. A simplest server-side examp...

Implementation of k8s deployment of docker container

Environment: (docker, k8s cluster), continue with...

How to set up a deployment project under Linux system

1. Modify the firewall settings and open the corr...

Use nexus as a private library to proxy docker to upload and download images

1. Nexus configuration 1. Create a docker proxy U...

Detailed explanation of Vue life cycle

Table of contents Why understand the life cycle W...

How to monitor global variables in WeChat applet

I recently encountered a problem at work. There i...

Docker large-scale project containerization transformation

Virtualization and containerization are two inevi...

Analysis and solution of the problem that MySQL instance cannot be started

Table of contents Preface Scenario Analysis Summa...

How to uninstall MySQL cleanly (tested and effective)

How to uninstall Mysql perfectly? Follow the step...

Implementation of built-in modules and custom modules in Node.js

1. Commonjs Commonjs is a custom module in nodejs...

An enhanced screenshot and sharing tool for Linux: ScreenCloud

ScreenCloud is a great little app you didn’t even...

HTML special character conversion table

character Decimal Character Number Entity Name --...

Understanding and using callback functions in JavaScript

Table of contents Overview What are callbacks or ...

HTML input file control limits the type of uploaded files

Add an input file HTML control to the web page: &...