<mariadb 数据库管理系统>
库:存放表格的目录Mariadb浅谈: MariaDB数据库管理系统是MySQL的一个分支, 主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL, 包括API和命令行,使之能轻松成为MySQL的代替品。 在存储引擎方面,使用XtraDB(英语:XtraDB)来代替MySQL的InnoDB。 MariaDB由MySQL的创始人Michael Widenius(英语:Michael Widenius)主导开发, 他早前曾以10亿美元的价格,将自己创建的公司MySQL AB卖给了SUN, 此后,随着SUN被甲骨文收购,MySQL的所有权也落入Oracle的手中。 MariaDB名称来自Michael Widenius的女儿Maria的名字。
1.安装
注意:操作之前先关闭火墙以及设定selinux为disable!
yum install mariadb-server -y systemctl start mariadb
2.安全初始化
*默认情况下数据库的网络接口是打开的 为了安全需要关闭此接口 vim /etc/my.cnf ###关闭网络接口 skip-networking=1 ###跳过网络对主机的安全性可以提高 systemctl restart mariadb *数据库起始状态设定信息是不安全的,需要做以下设定: mysql_secure_installation ###初始化数据库 #是否设置密码 #是否移除匿名用户 #是否禁止远程root用户登陆 #是否删除测试数据库 #是否刷新数据库 mysql -uroot -p Enter password:redhat
3.数据库的管理
mysqladmin -uroot -predhat password wrh
当超级用户密码忘记时:
systemctl stop mariadb
mysqld_safe --skip-grant-tables &
mysql
update mysql.user set Passwd=passwd('redhat') where User='root';
quit
[root@apache ~]# ps aux | grep mysql
kill -9 mysql的所有进程
systemctl start mariadb
4.数据库的管理
<1>建立 SHOW DATABASES; ###列出库 CREATE DATABASE westos; ###建立库 USE westos; ###进入库 CREATE TABLE linux ( ###建立表 -> username varchar(50) not null, -> password varchar(50) not null -> ); DESC linux; ###查看表结构 +----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+-------------+------+-----+---------+-------+ | username | varchar(50) | NO | | NULL | | | password | varchar(50) | NO | | NULL | | +----------+-------------+------+-----+---------+-------+ 2 rows in set (0.00 sec) MariaDB [westos]> INSERT INTO linux VALUES ('wrh','123'); ###插入数据到linux表中 MariaDB [westos]> SELECT * FROM linux; ###查询所有字段(类别)在linux表中 +----------+----------+ | username | password | +----------+----------+ | wrh | 123 | +----------+----------+ MariaDB [westos]> SELECT username,password from linux; ###查询指定字段(类别)在linux表中 +----------+----------+ | username | password | +----------+----------+ | wrh | 123 | +----------+----------+ 1 row in set (0.00 sec) <2>更改 *首先进入库 mysql MariaDB [(none)]> USE westos; ###进入库(westos) MariaDB [westos]> UPDATE linux SET password=password('qqq') where username='wrh'; ###更改wrh的密码为qqq并且将其以password方式加密 MariaDB [westos]> SELECT *FROM linux; +----------+-------------------------------------------+ | username | password | +----------+-------------------------------------------+ | wrh | *3D07E0D0A6AB1EB78DA1D222570ED89455FB7045 | +----------+-------------------------------------------+ MariaDB [westos]> ALTER TABLE linux ADD class varchar(20); ###添加class字段 MariaDB [westos]> SELECT *FROM linux -> ; +----------+-------------------------------------------+-------+ | username | password | class | +----------+-------------------------------------------+-------+ | wrh | *3D07E0D0A6AB1EB78DA1D222570ED89455FB7045 | NULL | +----------+-------------------------------------------+-------+ MariaDB [westos]> ALTER TABLE linux DROP CLASS; ###删除字段class MariaDB [westos]> SELECT *FROM linux; +----------+-------------------------------------------+ | username | password | +----------+-------------------------------------------+ | wrh | *3D07E0D0A6AB1EB78DA1D222570ED89455FB7045 | +----------+-------------------------------------------+ MariaDB [westos]> ALTER TABLE linux ADD age varchar(20) AFTER password; ###在password后面添加字段age MariaDB [westos]> SELECT *FROM linux; +----------+-------------------------------------------+------+ | username | password | age | +----------+-------------------------------------------+------+ | wrh | *3D07E0D0A6AB1EB78DA1D222570ED89455FB7045 | NULL | +----------+-------------------------------------------+------+ MariaDB [westos]> ALTER TABLE linux RENAME dream; ###重命名linux为dream MariaDB [westos]> SELECT *FROM dream; +----------+-------------------------------------------+------+ | username | password | age | +----------+-------------------------------------------+------+ | wrh | *3D07E0D0A6AB1EB78DA1D222570ED89455FB7045 | NULL | +----------+-------------------------------------------+------+ <3>删除 [root@apache ~]# mysql MariaDB [(none)]> USE westos; MariaDB [westos]> SELECT *FROM dream; +----------+-------------------------------------------+------+ | username | password | age | +----------+-------------------------------------------+------+ | wrh | *3D07E0D0A6AB1EB78DA1D222570ED89455FB7045 | NULL | +----------+-------------------------------------------+------+ MariaDB [westos]> DELETE FROM dream where username='wrh'; ###删除字段 MariaDB [westos]> SELECT *FROM dream; Empty set (0.00 sec) MariaDB [westos]> DrOP TABLE dream; ###删除表格 Query OK, 0 rows affected (0.32 sec) MariaDB [westos]> DESC dream; ERROR 1146 (42S02): Table 'westos.dream' doesn't exist MariaDB [westos]> DROP DATABASE westos; ###删除库 MariaDB [(none)]> SHOW DATABASES; ###列出库 +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ <4>用户的授权 MariaDB [westos]> CREATE USER wrh@'localhost' identified by 'westos'; ###创建本地用户通过密码 MariaDB [westos]> GRANT SELECT,INSERT on westos.* TO wrh@localhost; ###对本地用户授权 MariaDB [westos]> SHOW GRANTS FOR wrh@localhost; ###显示本地用户的授权 MariaDB [westos]> REVOKE INSERT ON westos.* FROM wrh@localhost; ###删除授权 create user lee@’%’ identified by ‘westos’; ##创建网络用户 ‘westos’通过密码
5.数据库的备份
mysqldump -uroot -pwestos westos > /mnt/westos.sql ###备份 mysqldump -uroot -pwestos westos --no-data ###只备份框架无数据 mysqldump -uroot -pwestos westos --all-database ###备份所有库 mysqldump -uroot -pwestos westos --all-database --no-data ###备份所有库的框架 恢复方式1: mysql -uroot -pwestos -e "CREATE DATABASE westos;" mysql -uroot -pwestos westos < /mnt/westos.sql ####创建再导入 恢复方式2: vim /mnt/westos.sql #CREATE DATABASE westos; #USE westos; mysql -uroot -pwestos < /mnt/westos.sql ###改配置文件
6.安装phpmyadmin数据库图形管理
<1>从网上下载phpMyAdmin-3.4.0-all-languages <2>yum search php yum install php yum install php-mysql -y <3>systemctl restart httpd <4>切换到下载目录 解压 tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 <5>cd /var/www/html/ mv /root/phpMyAdmin-3.4.0-all-languages ./ <6>mv /root/phpMyAdmin-3.4.0-all-languages mysqladmin ###重命名为mysqladmin <7> cd /var/www/html/mysqladmin/ vim Documentation.txt <8>cp config.sample.inc.php config.inc.php <9>vim config.inc.php $cfg['blowfish_secret']='ba17c1ec07d65003'; 测试: http://172.25.254.150/mysqladmin问题:
通过phpmyadmin设置数据库密码后若出现phpmyadmin拒绝访问的情况,
解决方法:
方法一:可以修改config.inc.php配置文件中的$cfg['Servers'][$i]['password'] = '你的密码';
方法二:将config.inc.php配置文件中的$cfg['Servers'][$i]['auth_type'] = 'config'; 修改为 $cfg['Servers'][$i]['auth_type'] = 'http';