欢迎投稿

今日深度:

Mariadb的安装和基本操作,mariadb基本操作

Mariadb的安装和基本操作,mariadb基本操作


一,Mariadb和Mysql的区别:
MariaDB不仅仅是Mysql的一个替代品,它的主要目的是创新和提高Mysql的技术。
MySQL之父Widenius先生离开了Sun之后,觉得依靠Sun/Oracle来发展MySQL,实在很不靠谱,于是决定另开分支,这个分支的名字叫做MariaDB。

二,mariadb的安装和基本操作:
1,安装并启用mariadb
[root@apache ~]# yum install -y mariadb-server
[root@apache ~]# systectl start mariadb
[root@apache ~]# mysql
MariaDB [(none)]> show databases;
MariaDB [(none)]> use mysql;
MariaDB [mysql]> show tables;
MariaDB [mysql]> select * from user;

2,安全初始化:
1)默认情况下,数据库的网络接口是打开的,为了安全需要把她关闭掉
[root@apache ~]# ss -antlpe| grep mysql
可以查看到3306端口
vim /etc/my.cnf
skip-networking=on
重启动,即可隐藏端口
[root@apache ~]# ss -antlpe| grep mysql
不可查看到3306端口

2)数据库起始状态设定是不安全的,需要自己初始化
mysql_secure_installation
设置mysql登陆密码,限制匿名登陆,远程登陆,移除测试库等
mysql -uroot -p

3,数据库的管理:
1)数据库修改密码:
[root@apache ~]# mysqladmin -uroot -pwestos password 123
[root@apache ~]# mysql -uroot -p123
2)忘记数据库密码:
[root@apache ~]# systemctl stop mariadb.service #关闭mariab
[root@apache ~]# mysqld_safe –skip-grant-tables & #跳过授权表
[root@apache ~]# mysql
MariaDB [(none)]> update mysql.user set Password=password(‘123’) where User =’root’; #在数据库中更新密码
[root@apache ~]# ps aux | grep mysql #关闭与mysql相关的进程
[root@apache ~]# systemctl start mariadb #重启
[root@apache ~]# mysql -uroot -p123 #用新密码登陆

4,数据库的建立
MariaDB [(none)]> SHOW databases; #列出库

MariaDB [(none)]> CREATE DATABASE hello; #创建库
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> USE hello; #使用库
Database changed
MariaDB [hello]> SHOW TABLES; #列出表
Empty set (0.00 sec)

MariaDB [hello]> CREATE TABLE compute (username varchar(20) not null,passwd varchar(20) not null); #创建表
Query OK, 0 rows affected (0.06 sec)

MariaDB [hello]> DESC compute; #查看表结构
+———-+————-+——+—–+———+——-+
| Field | Type | Null | Key | Default | Extra |
+———-+————-+——+—–+———+——-+
| username | varchar(20) | NO | | NULL | |
| passwd | varchar(20) | NO | | NULL |
MariaDB [hello]> INSERT INTO compute VALUES(‘lee’,’666’); #插入数据
Query OK, 1 row affected (0.04 sec)

MariaDB [hello]> INSERT INTO compute VALUES(‘zhang’,’777’);
Query OK, 1 row affected (0.04 sec)

MariaDB [hello]> INSERT INTO compute VALUES(‘tom’,’888’);
Query OK, 1 row affected (0.32 sec)

MariaDB [hello]> SELECT username,passwd from compute; #查看指定数据
+———-+——–+
| username | passwd |
+———-+——–+
| lee | 666 |
| zhang | 777 |
| tom | 888 |
+———-+——–+

5,数据库表的修改:
表内容修改:
MariaDB [hello]> update compute set password=password(‘999’) where username=’lee’; #修改用户密码
ERROR 1054 (42S22): Unknown column ‘password’ in ‘field list’
MariaDB [hello]> update compute set passwd=password(‘999’) where username=’lee’;
Query OK, 1 row affected, 1 warning (2.20 sec)
Rows matched: 1 Changed: 1 Warnings: 1

MariaDB [hello]> select * from compute;
+———-+———————-+
| username | passwd |
+———-+———————-+
| lee | *627B3E4116939F447D7 |
| zhang | 777 |
| tom | 888 |
+———-+———————-+
3 rows in set (0.00 sec)
加字段:
MariaDB [hello]> alter table compute add class varchar(20);
Query OK, 3 rows affected (2.44 sec)
Records: 3 Duplicates: 0 Warnings: 0

MariaDB [hello]> select * from compute;
+———-+———————-+——-+
| username | passwd | class |
+———-+———————-+——-+
| lee | *627B3E4116939F447D7 | NULL |
| zhang | 777 | NULL |
| tom | 888 | NULL |
+———-+———————-+——-+
删除以及在指定位置增加字段:
MariaDB [hello]> alter table compute drop class;
Query OK, 3 rows affected (0.53 sec)
Records: 3 Duplicates: 0 Warnings: 0

MariaDB [hello]> alter table compute add class varchar(20) after username;
Query OK, 3 rows affected (0.09 sec)
Records: 3 Duplicates: 0 Warnings: 0

MariaDB [hello]> select * from compute;
+———-+——-+———————-+
| username | class | passwd |
+———-+——-+———————-+
| lee | NULL | *627B3E4116939F447D7 |
| zhang | NULL | 777 |
| tom | NULL | 888 |
改表名:
MariaDB [hello]> alter table compute rename redhat;
Query OK, 0 rows affected (2.34 sec)

MariaDB [hello]> show tables;
+—————–+
| Tables_in_hello |
+—————–+
| redhat |

6.修改库名 表名
在/var/lib/mysql目录下也可以完成数据库的管理
删除表和库:
delete from redhat where username=’lee’ #删除表中用户

删除表:
MariaDB [hello]> drop table redhat;
Query OK, 0 rows affected (0.04 sec)

MariaDB [hello]> show tables;
Empty set (0.00 sec)

删除库:
MariaDB [hello]> drop database hello;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| performance_schema |

7,授权:
MariaDB [today]> create user liyuan@’localhost’ identified by ‘123’;
Query OK, 0 rows affected (0.00 sec) #创建数据库的管理用户

MariaDB [(none)]> grant select ,insert on today.* to liyuan@localhost; #为用户授>权

MariaDB [(none)]> show grants for liyuan@ocalhost; #查看用户的权力;

MariaDB [(none)]> revoke insert on today.* from liyuan@localhost; #移除用户的权
力;

8,数据库备份:(today是操作的数据库名)
mysqldump -uroot -p123 database > /mnt/database.sql #将database备份到/mnt>下,取名为database.sql
mysqldump -uroot -p123 today –no-data #只备份数据库的框架,不备份数>据,显示过程
mysqldump -uroot -p123 –all-database –no-data #备份所有数据库框架,显示过程

恢复方式1:
mysqldump -uroot -p123 -e”create database today;” #创建数据库
mysqldump -uroot -p123 today < /mnt/today.sql #倒入备份的内容
恢复方式2:
vim /mnt/database.sql
添加:
CREATE DATAASE today; #注意:today是所创建的数据库名
use today;
9,安装图形界面的mysq:
cd /var/www/html/
下载phpMysqlAdmin #下载phpMsqlAdmin到apache的默认发布目录下
tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2
mv phpMyAdmin-3.4.0-all-languages mysqladmin
cd mysqladmin/
yum install php php-mysql -y #安装插件
cp config.sample.inc.php config.inc.php #此处操作是根据Documentation.txt文件中
信息提供
vim Documentation.txt
139 cfg[‘blowfish_secret’] = ‘ba17c1ec07d65003’; #copy这串码
vim config.inc.php
17 $cfg[‘blowfish_secret’] = ‘ba17c1ec07d65003’; #加在此处
systemctl restart httpd

测试:
在浏览器;172.25.254.93/mysqladmin
即可以查看到图形界面的mysql,方便管理。

10,搭建论坛:
下载Discuz_X3.2_SC_UTF8.zip
cd /var/www/html
解压:unzip Discuz_X3.2_SC_UTF8.zip
chmod -R 777 upload/
打开浏览器:172.25.254.93/upload
可以完成论坛的安装,设置数据库的登陆用户和密码,以及管理员密码

www.htsjk.Com true http://www.htsjk.com/mariadb/33492.html NewsArticle Mariadb的安装和基本操作,mariadb基本操作 一,Mariadb和Mysql的区别: MariaDB不仅仅是Mysql的一个替代品,它的主要目的是创新和提高Mysql的技术。 MySQL之父Widenius先生离开了Sun之后,觉得依...
相关文章
    暂无相关文章
评论暂时关闭