CentOS7安装Mysql

一、系统环境

[root@localhost tmp]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core)

二、安装Mysql

yum install mysql
yum install mysql-server
yum install mysql-devel

在这里安装mysql-server会失败,报错如下:

No package mysql-server available.
Error: Nothing to do

这是由于CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了。

三、解决办法

1. 从官网下载mysql-server进行安装

 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

2. 设置密码
由于刚安装,mysql是没有密码的,所以我们需要设置一个密码

使用下面代码进行更改密码

set password for 'root'@'localhost' =password('password');

但是。。不知为何。。我失败了,哈哈哈!
解决办法如下:

第一步:进入数据库
[root@localhost ~]# mysql

第二步:改变用户数据库
mysql> use mysql;

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed

第三步:修改密码。记得密码要用password()函数进行加密,一定不要忘记!!!
mysql> update user set password=password('qwe123') where user='root';

Query OK, 1 row affected (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 0

第四步:刷新权限表
mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

第五步:退出mysql
mysql> quit
Bye

第六步:重启mysql服务
[root@localhost tmp]# service mysqld restart;

安装mysql完成

四、配置mysql

1. 编码

mysql的配置文件在centos根目录下的/etc/my.cnf
切换到etc目录下:

[root@localhost etc]# vi my.cnf

在文件末尾加上如下代码

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

需要加入
[mysql]
default-character-set =utf8

2. 配置远程连接
把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。

mysql> grant all privileges on *.* to root@'%'identified by 'password';

执行之后,所有的ip都可以通过root+password进行访问

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值