本文共 6369 字,大约阅读时间需要 21 分钟。
一。安装软件
#1.安装 [root@localhost ~]# yum install mariadb-server #2.重启服务: [root@localhost ~]# systemctl start mariadb #二。安全初始化 1)默认情况下,数据库的网络接口是打开的 为了安全需要关闭此接口 [root@localhost ~]# netstat -antlpe | grep mysql tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 27 40333 2064/mysqld 2)进入配置文件: [root@localhost ~]# vim /etc/my.cnf 10 skip-networking=1 #关闭接口 3)重启服务: [root@localhost ~]# systemctl restart mariadb [root@localhost ~]# mysql_secure_installation Set root password? [Y/n] y #设置跟密码是|否 Remove anonymous users? [Y/n] y #移除匿名用户是|否 Disallow root login remotely? [Y/n] y #不允许远程登录 Remove test database and access to it? [Y/n] y #不允许数据测试是|否 Reload privilege tables now? [Y/n] y [root@localhost ~]# mysql -uroot -p Enter password: 4)查看接口信息: netstat -antlpe | grep mysql 接口关闭 5)数据库起始状态设定信息是不安全的,需要作以下设定: 登录mysql)mysql -uroot -predhat) #三.数据库更改密码 1.mysqladmin -uroot -p旧密码 password 新密码 [root@localhost ~]# mysqladmin -uroot -pwestos password redhat[root@localhost ~]# mysql -uroot -predhat
2.当超级用户密码忘记时: systemctl stop mariadb [root@localhost ~]# mysqld_safe --skip-grant-tables & root@localhost ~]# 171122 20:26:48 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. 171122 20:26:48 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql[root@localhost ~]# mysql
[root@localhost ~]# ps aux | grep mysql root 3024 0.0 0.1 113248 1568 pts/0 S 20:26 0:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables mysql 3179 0.0 8.7 843944 86992 pts/0 Sl 20:26 0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-grant-tables --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock root 3325 0.0 0.0 112640 936 pts/0 R+ 20:31 0:00 grep --color=auto mysql 3.[root@localhost ~]# kill -9 3024 ##mysql的所有进程id [root@localhost ~]# kill -9 3179 [1]+ Killed mysqld_safe --skip-grant-tables [root@localhost ~]# [root@localhost ~]# ps aux | grep mysql root 3352 0.0 0.0 112640 936 pts/0 R+ 20:32 0:00 grep --color=auto mysql 4.[root@localhost ~]# systemctl start mariadb 5.[root@localhost ~]# mysql -uroot -pwestos 重启服务后测试 #四.建立数据库 1)建立(mysql里要以分号结尾) [root@localhost ~]# mysql -uroot -pwestos MariaDB [(none)]> SHOW DATABASES; ##列出库 MariaDB [(none)]> CREATE DATABASE westos; ##建立库 Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> SHOW DATABASES;
MariaDB [(none)]> USE westos; ##进入库 Database changed MariaDB [westos]> SHOW TABLES; ##列出表 Empty set (0.00 sec) MariaDB [westos]> CREATE TABLE linux (##建立表 -> username varchar(50) not null, -> password varchar(50) not null -> ); Query OK, 0 rows affected (0.13 sec)MariaDB [westos]> DESC linux; ##查看表结构
MariaDB [westos]> INSERT INTO linux VALUES ('qq','123') ##插入数据到linux 表中 -> ; MariaDB [westos]> select * from linux; ##查询所有字段在linux 表中 MariaDB [westos]> select username from linux; ##查询指定字段载linux 表中MariaDB [(none)]> SHOW DATABASES; ##列出库
CREATE TABLE linux (##建立表 USE westos; ##进入库 CREATE TABLE linux (##建立表 DESC linux; ##查看表结构 INSERT INTO linux VALUES ('qq','123') ##插入数据到linux 表中 select * from linux; ##查询所有字段在linux 表中 select username from linux; ##查询指定字段载linux 表中 2)更改MariaDB [westos]> UPDATE linux SET password=password('redhat'); #更改表内信息,更改password的加密密码
MariaDB [westos]> UPDATE linux SET password=password('redhat') where username='qq';#更改用户qq的password加密密码 MariaDB [westos]> UPDATE linux SET password='123';#更改password的密码MariaDB [westos]> ALTER TABLE linux ADD CLASS varchar(20); #在表的末尾添加一栏
MariaDB [westos]> ALTER TABLE linux DROP CLASS; #删除表中的指定栏 MariaDB [westos]> ALTER TABLE linux ADD class varchar(20) AFTER username;#在指定位置添加信息UPDATE linux SET password=password('redhat'); #更改表内信息,更改password的加密密码
UPDATE linux SET password=password('redhat') where username='qq';#更改用户qq的password加密密码 ALTER TABLE linux ADD CLASS varchar(20); #在表的末尾添加一栏ALTER TABLE linux DROP CLASS;
#删除表中的指定栏 3)删除 MariaDB [westos]> DELETE FROM linux where userroot='qq' -> ; MariaDB [westos]> DROP TABLE Linux; 4)用户授权 MariaDB [(none)]> CREATE USER qq@'localhost' identified by 'westos'; [root@localhost mysql]# mysql -uqq -p ![]( 5)[root@localhost mysql]# mysql -uroot -pwestos MariaDB [(none)]> GRANT SELECT,INSERT on westos.TO qq@'localhost'; #添加认证 MariaDB [(none)]> REVOKE INSERT ON westos. FROM qq@localhost; #移除插入数据功能 [root@localhost mysql]# mysql -uqq -p MariaDB [(none)]> REVOKE INSERT ON westos.* FROM qq@localhost; #移除插入数据功能 qq用户登录测试 6)数据库的备份 [root@localhost mysql]# mysqldump -uroot -pwestos --all-database #备份所有数据 [root@localhost mysql]# mysqldump -uroot -pwestos westos > /mnt/westos.sql#备份westos库信息导入 /mnt/westos.sql [root@localhost mysql]# mysqldump -uroot -pwestos westos MariaDB [(none)]> DROP DATABASE westos; [root@localhost mysql]# vim /mnt/westos.sql mysqldump -uroot -pwestos redhat> /mnt/redhat.sql#备份westos库信息导入 /mnt/westos.sql #备份redhat数据库信息,导入/mnt/redhat.sql [root@localhost mysql]# mysql -uroot -pwestosWelcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 21 Server version: 5.5.44-MariaDB MariaDB ServerCopyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> DROP DATABASE redhat;
Query OK, 1 row affected (0.11 sec)添加内容:
CREATE DATABASE redhat; USE redhat; 回复: [root@localhost mysql]# mysql -uroot -pwestos < /mnt/redhat.sql [root@localhost mysql]# mysql -uroot -pwestos vim /mnt/redhat.sql三。web端myssql搭建
1。下载phpMyAdmin-3.4.0-all-languages.tar.bz2并解压安装包[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls admin index.html phpMyAdmin-3.4.0-all-languages.tar.bz2 test.html cgi index.php test virtual 解压到/var/www/html/[root@localhost html]# tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 #解压
安装软件 [root@localhost mysqladmin]# yum install php-mysql.x86_64 root@localhost html]# rpm -qa | grep php 列出解压后的文件 配置文件的比对信息在此文件中 更改文件内容: 17 $cfg[[root@localhost mysqladmin]# vim config.inc.php 'blowfish_secret'] = 'ba17c1ec07d65003'; / YOU MUST FILL IN THIS FOR COOKIE AUTH! /[root@localhost mysqladmin]# yum install php-mysql.x86_64
[root@localhost mysqladmin]# systemctl restart httpd.service 测试mysql数据库搭建: 用root用户登录及密码 点击插入,即可添加内容,显示输入的所有内容 四。web端论坛搭建 1.下载压缩包并解压 [root@localhost html]# unzip Discuz_X3.2_SC_UTF8.zip 2.添加权限:root@localhost html]# chmod 777 upload/ 3.测试本文转自Uniqueh51CTO博客,原文链接:http://blog.51cto.com/13363488/2043689 ,如需转载请自行联系原作者