Centos7中安装Mysql8.0

环境:Centos7 + MySQL8.0

1、系统环境查看

cat /etc/redhat-release

2、安装

yum install mysql#看上面提示,安装的是mariadb
yum install mysql-server#no such command

Centos7中将Mysql数据库软件从默认程序列表中移除了,用mariadb代替了

3、安装(new)及启动

-ivh:i指将安装指的的rmp软件包,v表示安装时的详细信息,h表示安装期间出现#符号来显示母校的安装过程直至安装完成才停止
官网下载集合包.tar文件,解压

tar -xvf mysql-8.0.15-1.el7.x86_64.rpm-bundle.tar

安装:

rpm -ivh  mysql-community-common-8.0.15-1.el7.x86_64.rpm
rpm -ivh  mysql-community-libs-8.0.15-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.0.15-1.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-compat-8.0.15-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-8.0.15-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.15-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.15-1.el7.x86_64.rpm
rpm -ivh mysql-community-test-8.0.15-1.el7.x86_64.rpm

安装最快:

wget https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm	#配置安装源
sudo rpm -ivh mysql80-community-release-el7-2.noarch.rpm		#安装

输入账户密码:

root@localhost ~]# mysql -u用户名 -p密码
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

因:
没有去启动mysql
查看mysql是否启动:

[root@localhost ~]# ps aux | grep mysqld
root      3203  0.0  0.0 112708   976 pts/0    R+   20:25   0:00 grep --color=auto mysql

所示意为:没启动
查看mysql服务器状态:

 systemctl status mysqld.service

显示:

 mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2019-04-16 20:20:54 EDT; 5min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 3118 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=1/FAILURE)
  Process: 3095 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 3118 (code=exited, status=1/FAILURE)
   Status: "SERVER_BOOTING"
    Error: 2 (No such file or directory)

Apr 16 20:20:50 localhost.localdomain systemd[1]: Starting MySQL Server...
Apr 16 20:20:54 localhost.localdomain systemd[1]: mysqld.service: main process exited, code=exited, statu...LURE

去启动MySQL服务器:

sudo service mysqld start
Redirecting to /bin/systemctl start mysqld.service

启动成功

查看MySQL服务状态:

[root@localhost ~]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-04-16 21:01:09 EDT; 2min 46s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 2493 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 2575 (mysqld)
   Status: "SERVER_OPERATING"
   CGroup: /system.slice/mysqld.service
           └─2575 /usr/sbin/mysqld

Apr 16 21:00:58 localhost.localdomain systemd[1]: Starting MySQL Server...
Apr 16 21:01:09 localhost.localdomain systemd[1]: Started MySQL Server.

4、强化MySQL服务器

解决默认安装MySQL服务器中的几个安全问题,执行代码:

sudo mysql_secure_installation

此时返回:

Securing the MySQL server deployment.
Enter password for user root: 

需要输入MySQL给root用户的临时密码,执行:

sudo grep 'temporary password' /var/log/mysqld.log
2019-04-17T01:01:04.681765Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: qO_Q3roooCt;

注意注意:临时密码是:qO_Q3roooCt;
后面那个分号也是临时密码中的一部分
再次执行:sudo mysql_secure_installation
将临时密码粘贴过去

后面多个步骤按上面要求一步步设置

(1)MySQL中设置新的root用户密码(符号,大小写,数字,都要有,我是常用密码后加了;算符号)
(2)确认是否修改root用户密码:y
(3)是否想要继续进行密码保护:y
(4)默认情况下MySQL会有一个匿名用户,是否移除匿名用户:y
(5)是否禁止root用户的远程登陆:y
(6)是否删除测试数据库并访问它:y
(7)重载权限表将确保所有修改立时生效,是否现在就重载权限表:y
上述所设配置源码

[root@localhost ~]# sudo mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 
Error: Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost ~]# sudo grep 'temporary password' /var/log/mysqld.log
2019-04-17T01:01:04.681765Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: qO_Q3roooCt;
[root@localhost ~]# sudo mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 
Error: Access denied for user 'root'@'localhost' (using password: YES)
[root@localhost ~]# sudo mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 

The existing password for the user account root has expired. Please set a new password.

New password: 

Re-enter new password: 
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : y
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? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL 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? (Press y|Y for Yes, any other key for No) : y
 - 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? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

5、MySQL配置文件位置

[root@localhost ~]# ps aux|grep mysql|grep 'my.cnf'	#指使用默认位置配置
[root@localhost ~]# mysql --help|grep 'my.cnf'
                      order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值