1.什么是数据库 数据库就是个高级的表格软件
2.常见数据库 Mysql Oracle
3.Mysql (SUNmongodbdb2 sqlite sqlserver .......-----> Oracle)
4.mariadb
数据库中的常用名词
1.字段:表格中的表头
2.表:表格
3.库:存放表格的目录
4.查询:对表格中的指定内容进行查看
dnf install mariadb-server -y
systemctl enable --now mariadb
rpm -qc mariadb-server 查询mariadb配置文件/etc/my.cnf.d/mariadb-server.cnfll /
var/lib/mysql 数据目录,当需要重新安装mariadb时需要清理此目录或备份
[root@westoslinux112 yum.repos.d]# netstat -antlupe | grep mysql
tcp6 0 0 :::3306 :::* LISTEN 27 73763 17527/mysqld
[root@westoslinux112 yum.repos.d]# vim /etc/my.cnf.d/mariadb-server.cnf
编辑内容:
skip-netmorking=1
[root@westoslinux112 yum.repos.d]# systemctl restart mariadb
[root@westoslinux112 yum.repos.d]# netstat -antlupe | grep mysql
mysql_secure_installation
[root@Mariadb ~]# mysql 默认不需要密码,初始化完毕后需要
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@Mariadb ~]# mysql -uroot -p u 指定登陆用户 -p 密码
1.查看
SHOW DATABASES; ##显示库名称
USE mysql; ##进入mysql库
SHOW TABLES; ##显示库中的所有表
SELECT * FROM user; ##查询所有数据
SELECT Host,User,Password FROM user; ##查询指定字段
SELECT Host FROM mysql.user WHERE User='root'
2.新建
CREATE DATABASE westos; ##新建库
CREATE TABLE user ( ##新建表
username varchar(6) not null,
password varchar(30) not null
);
DESC userlist; ##显示表结构
INSERT INTO userlist VALUES ('user1','123'); #插入数据
SELECT * FROM userlist
FLUSH PRIVILEGES; #刷新数据库
3.更改
UPDATE userlist SET password='456' WHERE username='user2';
username='user2';ALTER userlist RENAME user;
SHOW TABLES;SHOW TABLES;
ALTER TABLE user add address VARCHAR(50);
ALTER TABLE user add age VARCHAR(4) AFTER password;
DESC user;
4.删除
DELETE FROM westos.user WHERE username='user1'
SELECT * FROM westos.user;
DROP TABLE westos.user;
DROP DATABASE westos;
SHOW DATABASES;
1.当密码没有改过时,可以执行命令
[root@westoslinux112 yum.repos.d]# mysqladmin -uroot -p password lee
Enter password: 输入旧密码[root@westoslinux112 yum.repos.d]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g. 修改成功2.当密码改过时,可执行命令:
systemctl stop mariadb
mysqld_safe --skip-grant-tables &UPDATE mysql.user SET Password=password('westos') WHERE User='root'; ##当未使用过mysladmin更改过
密码
UPDATE mysql.user SET authentication_string=password('westos') WHERE User='root'; ##当使用过mysladmin更改过密码
[root@westoslinux112 yum.repos.d]# systemctl stop mariadb
[root@westoslinux112 yum.repos.d]# mysqld_safe --skip-grant-tables &
[1] 31421
[root@westoslinux112 yum.repos.d]# 211110 21:02:43 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
211110 21:02:44 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[root@westoslinux112 yum.repos.d]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.17-MariaDB MariaDB Server
MariaDB [(none)]> UPDATE mysql.user SET authentication_string=password('westos') WHERE User='root';
[root@westoslinux112 yum.repos.d]# fg (crtl+z)
mysqld_safe --skip-grant-tables
^Z
[1]+ Stopped mysqld_safe --skip-grant-tables
[root@westoslinux112 yum.repos.d]# killall -9 mysqld_safe
[1]+ Killed mysqld_safe --skip-grant-tables
[root@westoslinux112 yum.repos.d]# ps aux | grep mysql
mysql 31515 0.2 10.5 1340688 88552 pts/1 Sl 21:02 0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mariadb/plugin --user=mysql --skip-grant-tables --log-error=/var/log/mariadb/mariadb.log --pid-file=/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root 31612 0.0 0.1 12108 1044 pts/1 S+ 21:09 0:00 grep --color=auto mysql
[root@westoslinux112 yum.repos.d]# kill -9 31515
[root@westoslinux112 yum.repos.d]# ps aux | grep mysql
root 31614 0.0 0.1 12108 988 pts/1 R+ 21:09 0:00 grep --color=auto mysql
[root@westoslinux112 yum.repos.d]# systemctl start mariadb
[root@westoslinux112 yum.repos.d]# mysql -uroot -p
Enter password: 密码修改成功
CREATE USER westos@localhost identified by 'westos'; 只能用localhost登陆
CREATE USER westos@% identified by '%'; ##可以通过网络或localhost登陆CREATE USER westos@localhost identified by 'westos';
SELECT User from mysql.user;
mysql -uroot -p
SHOW DATABASES; 没有权限什么都看不到
GRANT SELECT ON *.* TO westos@localhost; 添加查看权限
MariaDB [(none)]> SHOW GRANTS FOR westos@localhost;
+----------------------------------------------------------------------------------------------------------------+
| Grants for westos@localhost |
+----------------------------------------------------------------------------------------------------------------+
| GRANT SELECT ON *.* TO 'westos'@'localhost' IDENTIFIED BY PASSWORD '*28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96' | 添加成功GRANT INSECT ON *.* TO westos@localhost; 添加插入权限
---------------------+
| Grants for westos@localhost |
+------------------------------------------------------------------------------------------------------------------------+
| GRANT SELECT, INSERT ON *.* TO 'westos'@'localhost' IDENTIFIED BY PASSWORD '*28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96' | 添加成功MariaDB [(none)]> REVOKE INSERT ON *.* FROM westos@localhost; 移除插入权限
Query OK, 0 rows affected (0.000 sec)
mysql -uroot -pwestos -e "CREATE DATABASE westos;"
mysql -uroot -pwestos -e "CREATE TABLE westos.user(user varchar(10) not null,passwd varchar(50) not null);"
mysql -uroot -pwestos -e "INSERT INTO westos.user VALUES ('user1','123'),('user2','123');"
mysql -uroot -pwestos -e "SELECT * FROM westos.user;"
mysqldump -uroot -pwestos --all-database --no-data
mysqldump -uroot -pwestos westos > /mnt/westos.sql
ls /mnt
mysql -uroot -pwestos -e "DROP DATABASE westos"
[root@westoslinux112 squid]# mysql -uroot -pwestos westos < /mnt/westos.sql
ERROR 1049 (42000): Unknown database 'westos'
[root@westoslinux112 squid]# mysql -uroot -pwestos -e "CREATE DATABASE westos;"
[root@westoslinux112 squid]# mysql -uroot -pwestos westos < /mnt/westos.sql
[root@westoslinux112 squid]# mysql -uroot -pwestos -e "SELECT * FROM westos.user;"
+-------+--------+
| user | passwd |
+-------+--------+
| user1 | 123 |
| user2 | 123 |
+-------+--------+
[root@westoslinux112 squid]# mysql -uroot -pwestos -e "DROP DATABASE westos;"
[root@westoslinux112 squid]# vim /mnt/westos.sql
编辑内容:
CREATE DATABASE westos;
USE westos;
[root@westoslinux112 yum.repos.d]# mysql -uroot -pwestos < /mnt/westos.sql
[root@westoslinux112 squid]# mysql -uroot -pwestos -e "SELECT * FROM westos.user;"
+-------+--------+
| user | passwd |
+-------+--------+
| user1 | 123 |
| user2 | 123 |
+-------+--------+
phpmyadmin的安装
cd /mnt
[root@westoslinux112 mnt]# wget http://172.25.254.250/software/phpMyAdmin-3.4.0-all-languages.tar.bz2
dnf install httpd php php-mysqlnd -y
systemctl enable --now httpd
[root@westoslinux112 mnt]# tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 -C /var/www/html/
[root@westoslinux112 mnt]# ls /var/www/html/
phpMyAdmin-3.4.0-all-languages
[root@westoslinux112 mnt]# cd /var/www/html/
[root@westoslinux112 html]# mv phpMyAdmin-3.4.0-all-languages/ myadmin
[root@westoslinux112 html]# cd myadmin
[root@westoslinux112 myadmin]# less README
[root@westoslinux112 myadmin]# less Documentation.txt
[root@westoslinux112 myadmin]# cp config.sample.inc.php config.inc.php
[root@westoslinux112 myadmin]# vim config.inc.php
编辑内容:
$cfg['blowfish_secret'] = 'ba17c1ec07d65003'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */[root@westoslinux112 myadmin]# systemctl restart httpd
Job for httpd.service failed because the control process exited with error code.
See "systemctl status httpd.service" and "journalctl -xe" for details.
[root@westoslinux112 myadmin]# systemctl stop squid
[root@westoslinux112 myadmin]# systemctl restart httpd
在浏览器上访问172.25.254.112/myadmin