Build and import data of maraidb database under linux

Build environment:

sudo apt install mariadb-server

Set initial password:

UPDATE mysql.user SET password = PASSWORD(‘password’) WHERE USER =‘root’;

An error will be reported in the shell:

ERROR 1054 (42S22): Unknown column '‘root’' in 'where clause'

Because single quotes don't work, just replace them with double quotes in the shell:

Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

Change password login method:

MariaDB [(none)]> update mysql.user set plugin="mysql_native_password" where User="root";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

Update settings:

MariaDB [(none)]> FLUSH PRIVILEGES;

When logging in again should be:

mysql -u root -p

Create a read-only user:

GRANT SELECT ON *.* TO "username"@"%" IDENTIFIED BY "password";

View all user information:

MariaDB [(none)]> select *from mysql.user

Permission information:

Select_priv。确定用户是否可以通过SELECT命令选择数据。
Insert_priv。确定用户是否可以通过INSERT命令插入数据。
Update_priv。确定用户是否可以通过UPDATE命令修改现有数据。
Delete_priv。确定用户是否可以通过DELETE命令删除现有数据。
Create_priv。确定用户是否可以创建新的数据库和表。
Drop_priv。确定用户是否可以删除现有数据库和表。
Reload_priv。确定用户是否可以执行刷新和重新加载MySQL所用各种内部缓存的特定命令,包括日志、权限、主机、查询和表。
Shutdown_priv。确定用户是否可以关闭MySQL服务器。在将此权限提供给root账户之外的任何用户时,都应当非常谨慎。
Process_priv。确定用户是否可以通过SHOW
PROCESSLIST命令查看其他用户的进程。
File_priv。确定用户是否可以执行SELECT INTO OUTFILE和LOAD DATA
INFILE命令。
Grant_priv。确定用户是否可以将已经授予给该用户自己的权限再授予其他用户。例如,如果用户可以插入、选择和删除foo数据库中的信息,并且授予了GRANT权限,则该用户就可以将其任何或全部权限授予系统中的任何其他用户。
References_priv。目前只是某些未来功能的占位符;现在没有作用。
Index_priv。确定用户是否可以创建和删除表索引。
Alter_priv。确定用户是否可以重命名和修改表结构。
Show_db_priv。确定用户是否可以查看服务器上所有数据库的名字,包括用户拥有足够访问权限的数据库。可以考虑对所有用户禁用这个权限,除非有特别不可抗拒的原因。
Super_priv。确定用户是否可以执行某些强大的管理功能,例如通过KILL命令删除用户进程,使用SET
GLOBAL修改全局MySQL变量,执行关于复制和日志的各种命令。
Create_tmp_table_priv。确定用户是否可以创建临时表。
Lock_tables_priv。确定用户是否可以使用LOCK
TABLES命令阻止对表的访问/修改。
Execute_priv。确定用户是否可以执行存储过程。
Repl_slave_priv。确定用户是否可以读取用于维护复制数据库环境的二进制日志文件。此用户位于主系统中,有利于主机和客户机之间的通信。
Repl_client_priv。确定用户是否可以确定复制从服务器和主服务器的位置。
Create_view_priv。确定用户是否可以创建视图。
Show_view_priv。确定用户是否可以查看视图或了解视图如何执行。
Create_routine_priv。确定用户是否可以更改或放弃存储过程和函数。
Alter_routine_priv。确定用户是否可以修改或删除存储函数及函数。
Create_user_priv。确定用户是否可以执行CREATE
USER命令,这个命令用于创建新的MySQL账户。
Event_priv。确定用户能否创建、修改和删除事件。
Trigger_priv。确定用户能否创建和删除触发器。

There are two ways to create a database:

create database 数据库名;

create database 数据库名 character set 字符集;

After establishing the database, you should select the database and operate under the database

show databases;  //显示出所有的数据库

select database(); //查看当前选择的数据库

use 数据库名   //选择要操作的数据库 ,会提示Database changed

Create a data sheet:

create table 表名(
   字段名 类型(长度) 约束,
   字段名 类型(长度) 约束
);

Add, delete, modify:

增加列:

alter table tableName add columnName varchar(30)

修改列类型:

alter table tableName alter column columnName varchar(4000) 

修改列名称:

EXEC  sp_rename   'tableName.column1' , 'column2'  (把表名为tableName的column1列名修改为column2)  

删除列:

alter table tableName drop column columnName  

修改列长度:

alter table 表名 modify column 字段名 varchar(数量);

Insert data:

insert into 表名 (列名1,列名2,列名3..) values  (值1,值2,值3..); -- 向表中插入某些列

insert into 表名 values (值1,值2,值3..); --向表中插入所有列

Pay attention to single quotes when inserting data. This is very pitted. I have always reported an error. Unknown column '' in 'field list'. After counting for half a day, the number of data and the number of columns are always the same. However, it cannot be inserted. It turned out to be single quotes in English. It has become a single quote in Chinese, and I can't really see it if I don't look closely.

update data:

update 表名 set 字段名 = '***' where 字段名 = '**';

View the data table structure and list all data table names:

desc 表名;
show tables;

View the entire contents of the data sheet:

select *from 表名;

Delete the entire data table, delete the data of the entire table:

drop table xxxxxx;
truncate table xxxxxx;

Find some data and delete some data

select *from 表名 where 字段名 >= '' and 字段名 <= '';

delete from 表名 where 字段名 >= '' and 字段名 <= '';

Import the csv file into the database:

load data infile "/home/name.csv" into table tablename character utf8 gbk fields terminated by "," lines terminated by '\r\n';

If the Chinese is garbled, it is a coding problem, you can change the utf8 in the command to gbk.

Delete the data in the table:

delete from tablename;

Revoke user permissions:

REVOKE  ALL ON *.* FROM "username"@"%";

Database log reference

Detailed database log

Published 125 original articles · Like 31 · Visits 60,000+

Guess you like

Origin blog.csdn.net/Fiverya/article/details/94457816