1. The basic concept of the
database The database is an advanced form management
Common databases: mysql, oracle, SQL server
mysql
SUN------------>oracle
Common nouns in the database:
field: the header in the table
table: table
library: the directory where the table is stored
Query: view the specified content in the table
2. Installation of mariadb
dnf search mariadb
dnf install mariadb-server.x86_64 -y
rpm -ql mariadb #View
/var/lib/mysql
#Data directory /etc/my.cnf.d/ mariadb-server.cnf #Main configuration file
/usr/lib/systemd/system/mariadb.service #Service startup script
systemctl enable --now mariadb #Start the service and
initialize the database securely
mysal-secure-installation
Log in to
mysql -uroot -p #enter and then enter the password.
By default, the database is open to the outside world. Generally, in the enterprise, you need to close the
netstat -antulpe | grep mysql to
close the database network port. You need to edit the configuration file
vim /etc/my.cnf. d/mariadb-server.cnf
systemctl restart mariadb #Restart the service
At this point the port has been closed:
3. Basic management of the database
#Note: A semicolon should be marked after each command
1) View
SHOW DATABASES;
#Display the name of the library USE mysql; #Enter the mysql library
SHOW TABLES; #Display all tables in the library
SHOW TABLES FROM mysql; #Display the mysql library In all tables, this command does not need to enter the mysql database
SELECT * FROM user; #Query all data
SELECT Host,User,Password FROM user;
#Query the specified field SELECT Host FROM mysql.user WHERE User='root';
#Query CREATE DATABASE westos; #Create a library westos
CREATE TABLE westos.linux (username varchar(6) not null, password varchar(30) not null ); #Create a linux table in westos, the entries are username and password and are not empty
DESC westos. linux; #Display the linux table structure in the westos library
INSERT INTO westos.linux VALUES ('lee',123);
INSERT INTO westos.linux VALUES ('lee1',123),('lee2',123);
change the library Name, but it may cause data loss, it is not recommended to do this
cd /var/lib/mysql/
mv westos lee
systemctl restart mariadb
USE westos;
ALTER TABLE linux RENAME userlist; #Change the name of the linux table to userlist
ALTER TABLE linux ADD age varchar(4); #Add the age field to the linux table
ALTER TABLE linux DROP age; #Delete the age field
ALTER TABLE linux ADD age varchar(4) AFTER username; #After adding the age field to the username field
UPDATE linux SET age='123';
#Set all age to 123 UPDATE linux SET age='18' WHERE username='lee1' ; #Set the age of lee1 to 18
DELETE FROM linux WHERE username='lee' and age='123'; #Delete the table entry whose username is lee and age is equal to 123
DROP TABLE linux; #Delete linux table
4, database password management
1 ) Change the password (you already know the password)
mysqladmin -uroot -pwestos password The lee
password is unsafe, you can use another method:
mysqladmin -uroot -p password
2) Crack the database password (use if you forget it)
systemctl stop mariadb
mysqld_safe --skip-grant-tables &You
can enter directly without entering a password at this time:
mysql -uroot
UPDATE mysql.user SET authentication_string=password('123') WHERE User='root';
exit
ps aux | grep mysql #Check the mysql process
kill -9 xxxx
#Close the related process systemctl restart mariadb.
At this time, you can enter the password you changed.
5. User authorization
CREATE USER westos@localhost identified by'westos';
localhost means that this user can only log in to the database on this machine
CREATE USER westos@'%' identified by'westos';
% means that this user can log in to the database through the network, but the premise of the network login is that the database must open the network login interface.
Create an experimental environment:
CREATE DATABASE westostest;
CREATE TABLE westostest.userlist (
-> username varchar(10) not null,
-> password varchar(30) not null
-> );
INSERT INTO westostest.userlist VALUES('test','123');
GRANT SELECT ON westostest.* TO westos@localhost; #Grant westos@localhost user query power
SHOW GRANTS FOR westos@localhost; #Show grant westo@localhost user authority
. GRANT iNSERT ON westostest * TO westos @ localhost; # empowerment westos @ localhost user inserted
at this time westos user can insert
REVOKE iNSERT ON westostest * FROM westos @ localhost;. # cancel empowerment westos @ localhost user inserted
DROP user westos@'%'; #Delete user
SELECT Host,User FROM mysql.user; #At this time, you can see that there is no such user.
6. Database backup and recovery
Database backup:
mysqldump -uroot -pwestos mysql> /mnt /mysql.sql #Back up mysql database
mysqldump -uroot -pwestos --all-databases> /mnt/all.sql #Back up all databases
mysqldump -uroot -pwestos --all-databases --no-data> /mnt/all_nodata. sql #Back up all libraries but do not back up the structure of the database, that is, back up its structure
mysqldump -uroot -pwestos westostest> /mnt/westostest.sql #Back up the westostest database
Restore the database:
mysql -uroot -pwestos -e "CREATE DATABASE westostest;" #Create a database named westostest
mysql -uroot -pwestos westostest </mnt/ westostest.sql #Enter the previous backup into the new database.
At this point, you can see the database recovery:
7. Installation of phpmyadmin
dnf install httpd php php-mysqlnd -y
systemctl enable --now httpd
systemctl stop firewalld
cd /mnt/
cp phpMyAdmin-3.4.0-all-languages.tar.bz2 /var/www/html/
cd /var/www/html /
tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 -C /var/www/html/
mv phpMyAdmin-3.4.0-all-languages/ mysqladmin
cd mysqladmin/
less Documentation.txt #View the help file
cp config .sample.inc.php config.sample.php
access and log in at this time, you can see the database you created: