- 以下步骤需要确保虚拟机里的系统可以上网,并且以root账号登录系统。
- 安装完 CentOS 7 后第一件事情就是配置服务器网络,可以使用ifconfig命令查看当前网络信息。
- 但 CentOS 7 最小化默认是不提供该命令的,我们可以执行以下命令安装ifconfig工具。
yum install –y net-tools //完成后就可以使用ifconfig命令了
一、配置防火墙
- CentOS 7 默认使用的是firewall作为防火墙。
1、关闭防火墙或者为防火墙配置端口
方案一、直接关闭默认防火墙firewall(推荐)
#停止firewall服务
systemctl stop firewalld.service
#禁止firewall开机启动
systemctl disable firewalld.service
方案二、关闭默认防火墙,安装iptables防火墙,开启80、3306端口。(有需要时采用)
- CentOS 7 默认使用的是firewall作为防火墙,这里改为iptables防火墙。
然后配置防火墙,开启80、3306端口。
#停止firewall服务
systemctl stop firewalld.service
#禁止firewall开机启动
systemctl disable firewalld.service
#安装
yum install iptables-services
#编辑防火墙配置文件
vi /etc/sysconfig/iptables
####################【重点注意】###################
## 加入红色的两行代码,请注意位置一定要对应。
## 加入的代码,用#号的横线标注出来
###################################################
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
##################### 需要添加的代码 #######################
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
####################### 以上 #############################
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
:wq! #保存退出
#最后重启防火墙使配置生效
systemctl restart iptables.service
#设置防火墙开机启动
systemctl enable iptables.service
2、关闭Linux的安全子系统selinux
#修改配置文件
vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq! #保存退出
#使配置立即生效
setenforce 0
二、查看软件安装环境
1、安装之前,查看centos版本
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
2、检查是否安装了相关应用
检查apache
httpd -v
检查mysql
service mysqld start #结果是失败的
这里将要安装的是MariaDB数据库
说明:
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。
检查 MariaDB数据库状态
systemctl status mariadb
开启数据库
systemctl start mariadb
3、如果安装过,清理相关应用
如果有安装过,清理下
yum remove mysql
rm -f /etc/my.cnf
rpm -qa | grep httpd
三、安装LAMP服务
1、安装Apache
1.1 安装Apache HTTP服务器
安装httpd,必须安装依赖包 httpd-devel
[root@localhost ~]# yum -y install httpd httpd-devel
1.2 启动apache服务
[root@localhost ~]# systemctl start httpd
1.3 设置httpd服务开机启动
[root@localhost ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
1.4 查看服务状态
[root@localhost ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since 日 2020-08-09 22:53:26 CST; 8min ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 5347 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─5347 /usr/sbin/httpd -DFOREGROUND
├─5348 /usr/sbin/httpd -DFOREGROUND
├─5349 /usr/sbin/httpd -DFOREGROUND
├─5350 /usr/sbin/httpd -DFOREGROUND
├─5351 /usr/sbin/httpd -DFOREGROUND
└─5352 /usr/sbin/httpd -DFOREGROUND
8月 09 22:53:26 localhost.localdomain systemd[1]: Starting The Apache HTT...
8月 09 22:53:26 localhost.localdomain httpd[5347]: AH00558: httpd: Could ...
8月 09 22:53:26 localhost.localdomain systemd[1]: Started The Apache HTTP...
Hint: Some lines were ellipsized, use -l to show in full.
说明:如果上面选择了关闭防火墙,则省略下面两步
1.5 防火墙设置开启80端口(方案一,省略此步)
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=http
success
sroot@localhost ~]# firewall-cmd --permanent --zone=public --add-service=http
success
[root@localhost ~]# firewall-cmd --reload
success
1.6 确认80端口监听中(方案一,省略此步)
[root@localhost ~]# netstat -tulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:sunrpc 0.0.0.0:* LISTEN 707/rpcbind
tcp 0 0 localhost.locald:domain 0.0.0.0:* LISTEN 1431/dnsmasq
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN 1165/sshd
tcp 0 0 localhost:ipp 0.0.0.0:* LISTEN 1166/cupsd
tcp 0 0 localhost:smtp 0.0.0.0:* LISTEN 1435/master
tcp6 0 0 [::]:sunrpc [::]:* LISTEN 707/rpcbind
##################### httpd 这个是80端口 #####################
tcp6 0 0 [::]:http [::]:* LISTEN 5347/httpd
tcp6 0 0 [::]:ssh [::]:* LISTEN 1165/sshd
tcp6 0 0 localhost:ipp [::]:* LISTEN 1166/cupsd
tcp6 0 0 localhost:smtp [::]:* LISTEN 1435/master
udp 0 0 localhost.locald:domain 0.0.0.0:* 1431/dnsmasq
udp 0 0 0.0.0.0:bootps 0.0.0.0:* 1431/dnsmasq
udp 0 0 0.0.0.0:sunrpc 0.0.0.0:* 707/rpcbind
udp 0 0 0.0.0.0:mdns 0.0.0.0:* 714/avahi-daemon: r
udp 0 0 0.0.0.0:874 0.0.0.0:* 707/rpcbind
udp 0 0 0.0.0.0:52190 0.0.0.0:* 714/avahi-daemon: r
udp6 0 0 [::]:sunrpc [::]:* 707/rpcbind
udp6 0 0 [::]:874 [::]:* 707/rpcbind
查服务器IP地址
1.7 查询虚拟机服务器IP
[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:8c:95:33 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.235/24 brd 192.168.0.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::e18a:f9ef:3f82:90d5/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:3f:70:a7 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:3f:70:a7 brd ff:ff:ff:ff:ff:ff
1.8 浏览器登陆
- 在浏览器地址栏,输入服务器的IP地址
- 此处为:192.168.0.235
2、安装MySQL
2.1 安装mysql
- 安装MariaDB数据库
- MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。
- MariaDB的目的是完全兼容MySQL,包括API和命令行,是目前最受关注的MySQL数据库衍生版,也被视为开源数据库MySQL的替代品。
- 在CentOS7下安装MariaDB,如下所示:
- 安装 玛利亚数据库 mariadb 的四种组件,如下:
[root@localhost ~]# yum -y install mariadb mariadb-server mariadb-libs mariadb-devel
软件包 1:mariadb-5.5.65-1.el7.x86_64 已安装并且是最新版本
软件包 1:mariadb-server-5.5.65-1.el7.x86_64 已安装并且是最新版本
软件包 1:mariadb-libs-5.5.65-1.el7.x86_64 已安装并且是最新版本
软件包 1:mariadb-devel-5.5.65-1.el7.x86_64 已安装并且是最新版本
2.2 查询全部安装的玛利亚mariadb数据库
RPM是RedHat Package Manger(RedHat软件管理工具),是一种用于打包及安装工具
-qa代表query查询,a代表all全部
grep(global search rgular expression(RE) and print out the line):是一种强大的文本搜索工具
- rpm –qa
- 其中
- -q是查询一个包是否安装
- –a选项是查询所有已经安装的软件包。
- 显示区别:已经安装的rpm包不会显示后缀.rpm ,而未安装的包则显示后缀.rpm
- 一般查询一个安装包是否安装的的命令为:
- 例如:rpm -qa | grep screen
- 查询mariadb数据库是否全部安装
[root@localhost ~]# rpm -qa | grep maria
mariadb-5.5.65-1.el7.x86_64
mariadb-server-5.5.65-1.el7.x86_64
mariadb-libs-5.5.65-1.el7.x86_64
mariadb-devel-5.5.65-1.el7.x86_64
2.3 开启mysql服务
[root@localhost ~]# systemctl start mariadb
2.4 设置开机启动
[root@localhost ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
2.5 检查mysql状态
[root@localhost ~]# systemctl status mariadb
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since 一 2020-08-10 00:39:38 CST; 4min 5s ago
Main PID: 6604 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─6604 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─6704 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/my...
8月 10 00:39:35 localhost.localdomain mariadb-prepare-db-dir[6524]: 20081...
8月 10 00:39:36 localhost.localdomain mariadb-prepare-db-dir[6524]: 20081...
8月 10 00:39:36 localhost.localdomain mariadb-prepare-db-dir[6524]: PLEAS...
8月 10 00:39:36 localhost.localdomain mariadb-prepare-db-dir[6524]: To do...
8月 10 00:39:36 localhost.localdomain mariadb-prepare-db-dir[6524]: '/usr...
8月 10 00:39:36 localhost.localdomain mariadb-prepare-db-dir[6524]: '/usr...
8月 10 00:39:36 localhost.localdomain mariadb-prepare-db-dir[6524]: Alter...
8月 10 00:39:36 localhost.localdomain mysqld_safe[6604]: 200810 00:39:36 ...
8月 10 00:39:36 localhost.localdomain mysqld_safe[6604]: 200810 00:39:36 ...
8月 10 00:39:38 localhost.localdomain systemd[1]: Started MariaDB databas...
Hint: Some lines were ellipsized, use -l to show in full.
2.6 查询数据库端口及链接
- netstat命令用于显示与IP、TCP、UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况。
- netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TCP和UDP监听,进程内存管理的相关报告。
常用组合
netstat -lntup
说明: l:listening n:num t:tcp u:udp p:process
[root@localhost ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 707/rpcbind
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1431/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1165/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1166/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1435/master
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 6704/mysqld
tcp6 0 0 :::111 :::* LISTEN 707/rpcbind
tcp6 0 0 :::80 :::* LISTEN 5347/httpd
tcp6 0 0 :::22 :::* LISTEN 1165/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1166/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 1435/master
udp 0 0 192.168.122.1:53 0.0.0.0:* 1431/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 1431/dnsmasq
udp 0 0 0.0.0.0:111 0.0.0.0:* 707/rpcbind
udp 0 0 0.0.0.0:5353 0.0.0.0:* 714/avahi-daemon: r
udp 0 0 0.0.0.0:874 0.0.0.0:* 707/rpcbind
udp 0 0 0.0.0.0:52190 0.0.0.0:* 714/avahi-daemon: r
udp6 0 0 :::111 :::* 707/rpcbind
udp6 0 0 :::874 :::* 707/rpcbind
2.6 数据库安全设置
- MySQL安全配置向导
- mysql_secure_installation
- 安装完mysql-server 会提示可以运行mysql_secure_installation。
- 运行mysql_secure_installation会执行几个设置:
- 为root用户设置密码
- 删除匿名账号
- 取消root用户远程登录
- 删除test库和对test库的访问权限
- 刷新授权表使修改生效
- 通过这几项的设置能够提高mysql库的安全。
- 建议生产环境中mysql安装这完成后一定要运行一次mysql_secure_installation。
- 相关操作如下:
[root@localhost ~]# mysql_secure_installation
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] //#是否设置root用户密码,输入y并回车或直接回车
New password: //#设置root用户的密码
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] //#是否禁止root远程登录,根据自己的需求选择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] //#是否删除test数据库,直接回车
- 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!
2.7 重新设置允许MariaDB被远程访问
允许MariaDB被远程访问
firewall-cmd --add-service=mysql
2.8 登陆数据库测试
[root@localhost ~]# mysql -uroot -p
Enter password: //输入数据库登录密码
Welcome to the MariaDB monitor. Commands end with ; or \g. //命令以英文状态下的分号结尾。
Your MariaDB connection id is 11
Server version: 5.5.65-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases; //输入显示数据库的命令。
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> quit; //退出数据库。
Bye
3、安装PHP
3.1 安装php
[root@localhost ~]# yum -y install php
已安装:
php.x86_64 0:5.4.16-48.el7
作为依赖被安装:
libzip.x86_64 0:0.10.1-8.el7 php-cli.x86_64 0:5.4.16-48.el7 php-common.x86_64 0:5.4.16-48.el7
完毕!
3.2 查询已安装的PHP软件包都安装到何处
- 查询已安装软件包都安装到何处;
- 语法:rpm -ql 软件名
[root@localhost ~]# rpm -ql php
/etc/httpd/conf.d/php.conf
/etc/httpd/conf.modules.d/10-php.conf
/usr/lib64/httpd/modules/libphp5.so
/usr/share/httpd/icons/php.gif
/var/lib/php/session
3.3 将php与mysql关联起来
将php与mysql关联起来
[root@localhost ~]# yum -y install php-mysql
查询将php与mysql关联起来的软件包的位置
[root@localhost ~]# rpm -ql php-mysql
/etc/php.d/mysql.ini
/etc/php.d/mysqli.ini
/etc/php.d/pdo_mysql.ini
/usr/lib64/php/modules/mysql.so
/usr/lib64/php/modules/mysqli.so
/usr/lib64/php/modules/pdo_mysql.so
3.4 安装常用PHP模块
[root@localhost ~]# yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath
已安装:
libcurl-devel.x86_64 0:7.29.0-57.el7_8.1 php-bcmath.x86_64 0:5.4.16-48.el7 php-gd.x86_64 0:5.4.16-48.el7 php-ldap.x86_64 0:5.4.16-48.el7
php-mbstring.x86_64 0:5.4.16-48.el7 php-odbc.x86_64 0:5.4.16-48.el7 php-pear.noarch 1:1.9.4-21.el7 php-snmp.x86_64 0:5.4.16-48.el7
php-soap.x86_64 0:5.4.16-48.el7 php-xml.x86_64 0:5.4.16-48.el7 php-xmlrpc.x86_64 0:5.4.16-48.el7
作为依赖被安装:
net-snmp.x86_64 1:5.7.2-48.el7_8.1 net-snmp-agent-libs.x86_64 1:5.7.2-48.el7_8.1 php-process.x86_64 0:5.4.16-48.el7
t1lib.x86_64 0:5.1.2-14.el7 unixODBC.x86_64 0:2.3.1-14.el7
更新完毕:
curl.x86_64 0:7.29.0-57.el7_8.1
作为依赖被升级:
libcurl.x86_64 0:7.29.0-57.el7_8.1 net-snmp-libs.x86_64 1:5.7.2-48.el7_8.1
完毕!
3.5 测试PHP
[root@localhost html]# cd /var/www/html
[root@localhost html]# pwd
/var/www/html
[root@localhost html]# ls
########################### 注意 ##############################
注意:vi创建的文件,一定要以 .php 结尾。这要才能展示出来。
如果以 .info 结尾,则是以文件的形式打开,没有效果。
########################################################
创建并编辑php.info文件
vi info.php
按i键,开始编辑
使用vi编辑器,在php.info文件中写入如下内容:
<?php phpinfo();?>
或
<?php
phpinfo();
?>
按Esc键,退出编辑
保存并退出info.php文件
:wq
3.6 重启apache服务器
[root@localhost html]# systemctl restart httpd
3.7 测试PHP服务中info.php文件
在自己电脑浏览器输入
自己的服务器IP地址/info.php
例如:
192.168.0.235/info.php
- 你可以看到已经安装的模块;
四、补充内容:CentOS 7安装MySQL(仅供参考)
参考链接
centos7 mysql数据库安装和配置
https://www.cnblogs.com/starof/p/4680083.html
CentOS7安装MySQL(完整版)
一、系统环境
yum update升级以后的系统版本为
[root@yl-web yl]# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
二、mysql安装
背景资料:
查资料发现是CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了。
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。
开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。
MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。
一般网上给出的资料都是
#yum install mysql
#yum install mysql-server
#yum install mysql-devel
安装mysql和mysql-devel都成功,但是安装mysql-server失败,如下:
[root@yl-web yl]# yum install mysql-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.sina.cn
* extras: mirrors.sina.cn
* updates: mirrors.sina.cn
No package mysql-server available.
Error: Nothing to do
查资料发现是CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了。
1、方法一:安装mariadb
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。
安装mariadb,大小59 M。
yum install mariadb-server mariadb
mariadb数据库的相关命令是:
systemctl start mariadb #启动MariaDB
systemctl stop mariadb #停止MariaDB
systemctl restart mariadb #重启MariaDB
systemctl enable mariadb #设置开机启动
所以先启动数据库
systemctl start mariadb
然后就可以正常使用mysql了
[root@yl-web yl]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.41-MariaDB MariaDB Server
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>
2、方法二:官网下载安装mysql-server
安装mariadb后显示的也是 MariaDB [(none)]> ,可能看起来有点不习惯。下面是第二种方法。
# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server
安装成功后重启mysql服务。
# service mysqld restart
初次安装mysql,root账户没有密码。
[root@yl-web yl]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)
mysql>
设置密码
mysql> set password for 'root'@'localhost' =password('password');
Query OK, 0 rows affected (0.00 sec)
mysql>
不需要重启数据库即可生效。
在mysql安装过程中如下内容:
Installed:
mysql-community-client.x86_64 0:5.6.26-2.el7 mysql-community-devel.x86_64 0:5.6.26-2.el7
mysql-community-libs.x86_64 0:5.6.26-2.el7 mysql-community-server.x86_64 0:5.6.26-2.el7
Dependency Installed:
mysql-community-common.x86_64 0:5.6.26-2.el7
Replaced:
mariadb.x86_64 1:5.5.41-2.el7_0 mariadb-devel.x86_64 1:5.5.41-2.el7_0 mariadb-libs.x86_64 1:5.5.41-2.el7_0
mariadb-server.x86_64 1:5.5.41-2.el7_0
所以安装完以后mariadb自动就被替换了,将不再生效。
rpm -qa |grep mariadb
三、配置mysql
1、编码
mysql配置文件为/etc/my.cnf
最后加上编码配置
[mysql]
default-character-set =utf8
这里的字符编码必须和/usr/share/mysql/charsets/Index.xml中一致。
2、远程连接设置
把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。
mysql> grant all privileges on *.* to root@'%'identified by 'password';
如果是新用户而不是root,则要先新建用户
mysql>create user 'username'@'%' identified by 'password';
此时就可以进行远程连接了。
参考文献:
Centos 7安装LAMP环境
https://blog.csdn.net/wfx15502104112/article/details/80401944
centos7用yum搭建LAMP环境
https://www.cnblogs.com/me80/p/7218883.html
centos 7.2安装 lamp环境
https://www.cnblogs.com/xiaqiuchu/articles/10043630.html
CentOS 7搭建LAMP环境
https://www.jianshu.com/p/fabe5842c0e1
yum 配置详细参数及含义
https://blog.csdn.net/lwqjn/article/details/25865323
Linux netstat命令详解
https://www.cnblogs.com/ftl1012/p/netstat.html
mysql_secure_installation 安全配置向导
https://blog.csdn.net/qq_32786873/article/details/78846008