Get the App
SLTechnology News&Howtos  ›  Database  › 

What are the basic commands that MySQL must have

Shulou Source: shulou.com Published: 2022-06-01 17:46:47 09月18日 Update

Below I will give you a brief talk about what MySQL must know the basic commands, you know before the related similar topic content? If you are interested, take a look at this article together. I believe that after reading which MySQL basic commands will be helpful to everyone.

1.1 Log in to the database.

mysql -uroot -poldboy123 -S /data/3306/mysql.sock

1.2 View the database version and what the current logged-in user is.

select version();select user();

1.3 Create a database oldboy of GBK character sets and view the complete statements of the library.

create database oldboy character set gbk collate gbk_chinese_ci;show create database oldboy\G

1.4 Create user oldboy to manage database oldboy.

grant all on oldboy.* to 'oldboy'@'localhost' identified by 'oldboy123';

1.5 See what permissions the created user oldboy has.

show grants for oldboy@localhost\G

1.6 See which users are currently in the database.

select user,host from mysql.user;

1.7 Create admin account admin

grant all on *.* to 'admin'@'localhost' identified by 'admin123' with grant option;

1.8 Enter the oldboy database

use oldboy;

1.9 Create test table: innodb engine, character set GBK, field id int(4) and name varchar(16), view table structure and SQL statement.

create table test (id int(4),name varchar(16))ENGINE=innodb DEFAULT CHARSET=gbk;desc test; #1;

1.13 Change the name oldboy with data id equal to 1 to oldgirl.

update test set name='oldgirl' where id=1;

1.14 Insert an age field of type tinyint(2) before the field name.

alter table test add name tinyint(2) after id;

1.15 Backup oldboy and mysql libraries.

mysqldump -uroot -poldboy123 -S /data/3306/mysql.sock --events -B oldboy mysql >/opt/bak_$(date +%F).sql

egrep -v "#|^$|--|\/" /opt/bak_2017-06-06-13:36:37.sql

1.16 Delete all data from the table and view it.

truncate table test; #

Tags: Data characters character sets fields databases indexes commands queries mobile phones files users foundations lines garbled names clients clients types statements services Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MariaDB Redmi macOS Microsoft