Linux中搭建mysql数据库及其管理,web端论坛的搭建
一。安装软件
#1.安装
[[email protected]ocalhost ~]# yum install mariadb-server
#2.重启服务:
[[email protected] ~]# systemctl start mariadb
#二。安全初始化
1)默认情况下,数据库的网络接口是打开的
为了安全需要关闭此接口
[[email protected] ~]# netstat -antlpe | grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 27 40333 2064/mysqld
2)进入配置文件:
[[email protected] ~]# vim /etc/my.cnf
10 skip-networking=1 #关闭接口
3)重启服务:
[[email protected] ~]# systemctl restart mariadb
[[email protected] ~]# 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
[[email protected] ~]# mysql -uroot -p
Enter password:
4)查看接口信息: netstat -antlpe | grep mysql
接口关闭
5)数据库起始状态设定信息是不安全的,需要作以下设定:
登录mysql
)mysql -uroot -predhat
)
#三.数据库更改密码
1.mysqladmin -uroot -p旧密码 password 新密码
[[email protected] ~]# mysqladmin -uroot -pwestos password redhat
[[email protected] ~]# mysql -uroot -predhat
2.当超级用户密码忘记时:
systemctl stop mariadb
[[email protected] ~]# mysqld_safe --skip-grant-tables &
[email protected] ~]# 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
[[email protected] ~]# mysql
[[email protected] ~]# 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.[[email protected] ~]# kill -9 3024 ##mysql的所有进程id
[[email protected] ~]# kill -9 3179
[1]+ Killed mysqld_safe --skip-grant-tables
[[email protected] ~]#
[[email protected] ~]# ps aux | grep mysql
root 3352 0.0 0.0 112640 936 pts/0 R+ 20:32 0:00 grep --color=auto mysql
4.[[email protected] ~]# systemctl start mariadb
5.[[email protected] ~]# mysql -uroot -pwestos
重启服务后测试
#四.建立数据库
1)建立(mysql里要以分号结尾)
[[email protected] ~]# 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 [email protected]'localhost' identified by 'westos';
[[email protected] mysql]# mysql -uqq -p
[[email protected] mysql]# mysql -uroot -pwestos
MariaDB [(none)]> GRANT SELECT,INSERT on westos.TO [email protected]'localhost'; #添加认证
MariaDB [(none)]> REVOKE INSERT ON westos. FROM [email protected]; #移除插入数据功能
[[email protected] mysql]# mysql -uqq -p
MariaDB [(none)]> REVOKE INSERT ON westos.* FROM [email protected]; #移除插入数据功能
qq用户登录测试
6)数据库的备份
[[email protected] mysql]# mysqldump -uroot -pwestos --all-database #备份所有数据
[[email protected] mysql]# mysqldump -uroot -pwestos westos > /mnt/westos.sql#备份westos库信息导入 /mnt/westos.sql
[[email protected] mysql]# mysqldump -uroot -pwestos westos
MariaDB [(none)]> DROP DATABASE westos;
[[email protected] mysql]# vim /mnt/westos.sql
mysqldump -uroot -pwestos redhat> /mnt/redhat.sql#备份westos库信息导入 /mnt/westos.sql #备份redhat数据库信息,导入/mnt/redhat.sql
[[email protected] 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 Server
Copyright (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;
回复:
[[email protected] mysql]# mysql -uroot -pwestos < /mnt/redhat.sql
[[email protected] mysql]# mysql -uroot -pwestos
vim /mnt/redhat.sql
三。web端myssql搭建
1。下载phpMyAdmin-3.4.0-all-languages.tar.bz2并解压安装包
[[email protected] ~]# cd /var/www/html/
[[email protected] html]# ls
admin index.html phpMyAdmin-3.4.0-all-languages.tar.bz2 test.html
cgi index.php test virtual
解压到/var/www/html/
[[email protected] html]# tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 #解压
安装软件
[[email protected] mysqladmin]# yum install php-mysql.x86_64
[email protected] html]# rpm -qa | grep php
列出解压后的文件
配置文件的比对信息在此文件中
更改文件内容:
17 $cfg[[[email protected] mysqladmin]# vim config.inc.php
'blowfish_secret'] = 'ba17c1ec07d65003'; / YOU MUST FILL IN THIS FOR COOKIE AUTH! /
[[email protected] mysqladmin]# yum install php-mysql.x86_64
[[email protected] mysqladmin]# systemctl restart httpd.service
测试mysql数据库搭建:
用root用户登录及密码
点击插入,即可添加内容,显示输入的所有内容
四。web端论坛搭建
1.下载压缩包并解压
[[email protected] html]# unzip Discuz_X3.2_SC_UTF8.zip
2.添加权限:[email protected] html]# chmod 777 upload/
3.测试
本文转自Uniqueh51CTO博客,原文链接:http://blog.51cto.com/13363488/2043689 ,如需转载请自行联系原作者