banner
破影岚歌

破影岚歌的博客

bilibili
twitter
github

16. MariaDB Database

CentOS7 Database MariaDB (MySQL)#

Objective 1#

Install MariaDB and manage MariaDB service processes

Packages: mariadb-server (server-side); mariadb (client-side)

systemctl start mariadb				#Start MariaDB
systemctl enable mariadb			#Enable MariaDB to start on boot
#Other commands are similar

Objective 2#

Connect to MariaDB database and set up administrator (root, which is the MariaDB admin account, not the Linux admin account, just the same name)

Connect to mysql

Exit exit

Initialize MariaDB mysql_secure_installation

Change MariaDB password mysqladmin -u user -pold_password password new_password Note: no space between -p and old password


Objective 3#

Manage databases (query, create, drop, use)#

create database xxx;			#Create database xxx
show databases;						#Query databases
drop database xxx;				#Drop database xxx
use xxx;									#Use database xxx

Note: add a semicolon at the end of each statement


Objective 4#

Manage tables in the database (query, create, drop)#

show tables;				#Query tables
create table student(Sno char(8), Sname varchar(8), Sage int, Saddress varchar(20));			#Create a student table
drop table student;		#Drop table
show columns from student;		#Query table structure

Objective 5#

Manage data in tables (query, insert, delete, update)#

Query: select * from student;

Insert: insert into student values('001', 'zhang', '18', 'hz');

Update: update student set saddress='hangzhou' where Sno='001';

Delete: delete from student where Sno='000';

Objective 6#

Backup and restore databases#

Backup: mysqldump -u root -p123456 school > /root/school.sql

Restore: mysql -u root -p123456 school < /root/school.sql

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.