什么是mariadb?
MariaDB數(shù)據(jù)庫管理系統(tǒng)是MySQL的一個(gè)分支,主要由開源社區(qū)在
維護(hù),采用GPL授權(quán)許可 MariaDB的目的是完全兼容MySQL,包括API和
命令行,使之能輕松成為MySQL的代替品。在存儲(chǔ)引擎方面,使用XtraDB
(英語:XtraDB)來代替MySQL的InnoDB。 MariaDB由MySQL的
創(chuàng)始人Michael Widenius(英語:Michael Widenius)主導(dǎo)開發(fā),他早
前曾以10億美元的價(jià)格,將自己創(chuàng)建的公司MySQL AB賣給了SUN,此后,
隨著SUN被甲骨文收購(gòu),MySQL的所有權(quán)也落入Oracle的手中。MariaDB
名稱來自Michael Widenius的女兒Maria的名字。
1.Mariadb安裝
1-1安裝mariadb和mariadb-client組件:
# yum groupinstall -y mariadb mariadb-client
1-2啟動(dòng)mariadb服務(wù):
# systemctl start mariadb ; systemctl enable mariadb
[root@server1 ~]# ss -antple|grep mysql
LISTEN 0 50 *:3306 *:*
users:(("mysqld",2622,13)) uid:27 ino:36479 sk:ffff8800235a0000 <->
1-4編輯/etc/my.cnf文件,在[mysqld]中加入以下參數(shù):
skip-networking=1
1-5# systemctl restart mariadb
# ss -antlp |grep mysql 此時(shí)只允許通過套接字文件進(jìn)行本地連接,阻斷
所有來自網(wǎng)絡(luò)的tcp/ip連接。
2.使用mysql_secure_installation工具進(jìn)行數(shù)據(jù)庫安全設(shè)置,根據(jù)提示完成
操作:
# mysql_secure_installation
[root@server1 ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
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@server1 ~]#
3.登錄數(shù)據(jù)庫:
# mysql -u root -p Enter password: redhat MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.00 sec) MariaDB [(none)]> quit
4.數(shù)據(jù)庫基本操作SQL
show databases; 顯示數(shù)據(jù)庫 use mysql; 進(jìn)入數(shù)據(jù)庫 show tables; 顯示數(shù)據(jù)庫中的表 desc user; 查看user表的數(shù)據(jù)結(jié)構(gòu) flush privileges; 刷新數(shù)據(jù)庫信息 select host.user,password from user; 查詢user表中的host,user,password字段 create database westos; 創(chuàng)建westos數(shù)據(jù)庫 use westos; create table linux( 創(chuàng)建表,username,password字段 username varchar(15) not null, password varchar(15) not null ); select * from mysql.user; 查詢mysql庫下的user表中的所以 alter table linux add age varchar(4); 添加age字段到linux表中 alter table linux drop age; alter table linux add age varchar(4) after username; show tables; desc linux; insert into linux values ('user1','passwd1'); 在linux表中插入值為username = user1,password = password1 update linux set password=password('passwd2') where username=user1; 更新linux表中user1 的密碼為password2 delete from linux where username=user1; 刪除linux表中user1的所以內(nèi)容
5.mysql 密碼恢復(fù)
1)#systemctl stop mariadb
2)#mysql_safe --skip-grant &
3)#mysql
update mysql.user set password=password('westos') where user='root'; 更新mysql.user 表中條件為root用戶的密碼為加密westos 4)killall -9 mysqld_safe ps -aux | grep mysql kill -9 **** 5)systemctl start mariadb
6.用戶和訪問權(quán)限
創(chuàng)建用戶CREATE USER wxh@localhost identified by 'westos'; CREATE USER lee@'%' identified by 'redhat';用戶授權(quán)GRANT INSERT,UPDATE,DELETE,SELECT on mariadb.* to wxh@localhost; GRANT SELECT on mariadb.* lee@'%';重載授權(quán)表FLUSH PRIVILEGES;查看用戶授權(quán)SHOW GRANTS FOR wxh@localhost;撤銷用戶權(quán)限REVOKE DELETE,UPDATE,INSERT on mariadb.* from wxh@localhost;刪除用戶DROP USER wxh@localhost;
7.備份與恢復(fù)
備份# mysqldump -uroot -predhat westos > westos.dump # mysqldump -uroot -predhat --all-databases > backup.dump # mysqldump -uroot -predhat --no-data westos > westos.dump ##只備份框架,不備份數(shù)據(jù)。恢復(fù)# mysqladmin -uroot -predhat create db2 或 mysql -uroot -predhat -e 'CREATE DATABASE db2;' # mysql -uroot -predhat db2 < westos.dump
8.網(wǎng)頁管理數(shù)據(jù)庫
1)裝軟件http,php,php-mysql (phpMyAdmin-3.4.0-all-languages) 2)cd /var/www/html 3)下載解壓php壓縮包, 4)mv phpMyAdmin-3.4.0-all-languages/ myadmin 5)cd myadmin/ 6)cp config.sample.inc.php config.inc.php vim config.inc.php $cfg['blowfish_secret'] = ''; ==>$cfg['blowfish_secret'] = 'steven'; 7)systemctl restart httpd 8)172.252.254.X/myadmin
數(shù)據(jù)庫備份腳本
#!/bin/bash HELLO=$1.`date +%Y-%m-%d`.sql read -p "please input your user name :" NAME read -s -p "please input the user password :" PASSWORD mkdir /mydata &>/dev/null touch /mydata/$HELLO mysqldump -u$NAME -p$PASSWORD $1 >/mydata/$HELLO echo -e "\nThe backup successful!"
新聞標(biāo)題:mariadb數(shù)據(jù)庫服務(wù)
文章路徑:http://jinyejixie.com/article44/jjpche.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、網(wǎng)站策劃、微信小程序、電子商務(wù)、關(guān)鍵詞優(yōu)化、網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)