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 as mentioned above
Objective 2#
Connect to MariaDB database and set up administrator (root, here root 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: semicolon required 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 database#
Backup: mysqldump -u root -p123456 school > /root/school.sql
Restore: mysql -u root -p123456 school < /root/school.sql