日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql 数据库的基本管理

發(fā)布時間:2024/9/3 数据库 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql 数据库的基本管理 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

###### 1.數(shù)據(jù)庫的介紹 ######
1.什么是數(shù)據(jù)庫
數(shù)據(jù)庫就是個高級的表格軟件

2.常見數(shù)據(jù)庫
Mysql Oracle?? ?mongodb? db2 sqlite sqlserver .......

3.Mysql (SUN? -----> Oracle)

4.mariadb

###### 2.mariadb的安裝 ######
dnf install mariadb-server.x86_64 -y


###### 3.軟件基本信息 ######
mariadb.service?? ??? ??? ??? ?##啟動服務(wù)
3306?? ??? ??? ??? ??? ?##默認(rèn)端口號
/etc/my.cnf.d/mariadb-server.cnf?? ?##主配置文件
/var/lib/mysql?? ??? ??? ??? ?##數(shù)據(jù)目錄,當(dāng)需要重新安裝mariadb時需要清理此目錄或備份

###### 4.數(shù)據(jù)庫開啟? ######
systemctl enable --now mariadb

###### 5.數(shù)據(jù)庫的安全初始化 ######
1.關(guān)閉數(shù)據(jù)庫開放端口
vim /etc/my.cnf.d/mariadb-server.cnf
[mysqld]
skip-networking=1

systemctl restart mariadb

ss -antlupe? | grep mysql?? ?#此命令查詢不到端口

2.執(zhí)行安全初始化腳本
mysql_secure_installation

[root@localhost1 ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
????? SERVERS IN PRODUCTION USE!? PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.? If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
?... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.? This is intended only for testing, and to make the installation
go a bit smoother.? You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]
?... Success!

Normally, root should only be allowed to connect from 'localhost'.? This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]
?... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.? This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]
?- Dropping test database...
?... Success!
?- Removing privileges on test database...
?... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
?... Success!

Cleaning up...

All done!? If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

?

[root@Mariadb ~]# mysql?? ??? ??? ?##默認(rèn)不需要密碼,初始化完畢后需要
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[root@Mariadb ~]# mysql -uroot -p?? ?## -u 指定登陸用戶 -p 密碼

###### 6.數(shù)據(jù)庫的基本管理 ######
1.查看
SHOW DATABASES;?? ??? ??? ??? ?##顯示庫名稱
USE mysql;?? ??? ??? ??? ?##進入mysql庫
SHOW TABLES;?? ??? ??? ??? ?##顯示庫中的所有表
SELECT * FROM user;?? ??? ??? ?##查詢所有數(shù)據(jù)
SELECT Host,User,Password FROM user;?? ?##查詢指定字段

?

2.新建
CREATE DATABASE westos;?? ??? ??? ?##新建庫
CREATE TABLE linux (
username varchar(6) not null,
password varchar(30) not null
);?? ??? ??? ??? ??? ??? ?##新建表
DESC linux;?? ??? ??? ??? ??? ?##顯示表結(jié)構(gòu)
INSERT INTO linux VALUES ('user1','123'); ?? ?#插入數(shù)據(jù)
FLUSH PRIVILEGES;?? ??? ??? ??? ?#刷新數(shù)據(jù)庫

?

3.更改
ALTER TABLE? linuxRENAMEredhat;
ALTER TABLE redhat ADD age varchar(4) AFTER password;
ALTER TABLE?redhat DROP age;
UPDATE redhat SET password='g' WHERE username='user2';


4.刪除
DELETE from redhat where username='user2' and password='g';
DROP TABLE redhat;
DROP DATABASE westos;

###### 7.數(shù)據(jù)密碼管理 ######
1.數(shù)據(jù)密碼更改
mysqladmin? -uroot -pwestos password lee

2.數(shù)據(jù)庫密碼破解
systemctl stop mariadb
mysqld_safe --skip-grant-tables &
UPDATE mysql.user set Password=password('lee') WHERE User='root';?? ??? ?##RHEL7
UPDATE mysql.user set authentication_string=password('lee') WHERE User='root';?? ?##RHEL8

flush privileges;

ps aux | grep mariadb
kill -9 mysql的所有進程
systemctl start mariadb

###### 8.用戶授權(quán) #####
CREATE USER lee@localhost identified by 'lee';?? ?##只能用localhost登陸
CREATE USER lee@% identified by '%';?? ??? ?##可以通過網(wǎng)絡(luò)或localhost登陸
GRANT INSERT,SELECT? ON westos.* TO lee@localhost;
SHOW GRANTS for lee@localhost;
REVOKE SELECT ON westos.* FROM lee@localhost;
DROP user lee@localhost;

?

###### 9.數(shù)據(jù)庫的備份 #####
mysqldump -uroot -pwestos --all-database
mysqldump -uroot -p westos --all-database --no-data??? 沒有數(shù)據(jù)信息

備份

mysqldump -uroot -pwestos westos
mysqldump -uroot -pwestos westos > /mnt/westos.sql
?

恢復(fù)

test1

mysql -uroot -pwestos -e "DROP DATABASE westos;"??? 先進行庫刪除,以便驗證下一步恢復(fù)。

mysql -uroot -pwestos -e "create database westos;"創(chuàng)建庫
mysql -uroot -pwestos westos < /mnt/westos.sql? 恢復(fù)庫中的數(shù)據(jù)信息

test2

mysql -uroot -pwestos -e "DROP DATABASE westos;"???

vim /mntwestos.sql

CREATE DATABASE westos;

USE westos;

mysql -uroot -pwestos < /mnt/westos.sql

?


###### 10.phpmyadmin的安裝 #####
dnf install httpd php php-mysqlnd -y
systemctl enable --now httpd
systemctl stop firewalld
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
mv phpMyAdmin-3.4.0-all-languages/ mysqladmin
cd mysqladmin
cp config.sample.inc.php? config.inc.php
vim config.inc.php
$cfg['blowfish_secret'] = 'ba17c1ec07d65003';
systemctl restart httpd.server

?

?

?

firefox http://192.168.0.12/mysqladmin

?

總結(jié)

以上是生活随笔為你收集整理的mysql 数据库的基本管理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。