安装环境:
[[email protected] rookie]# lsb_release -a LSB Version: :core-4.1-amd64:core-4.1-noarch Distributor ID: CentOS Description: CentOS Linux release 7.4.1708 (Core) Release: 7.4.1708 Codename: Core |
安装MySQL数据库
#yum install mysql-server #yum install mysql-devel #yum install mysql |
安装mysql-server时出现如下错误:
[[email protected] rookie]# yum install mysql-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.btte.net
* updates: mirrors.btte.net
No package mysql-server available
查资料发现是CentOS7版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了。
解决办法:
1、完全卸载MariaDB
卸载Mariadb数据库
查询所安装的MariaDB组件:
[[email protected] rookie]# rpm -qa | grep Maria*
MariaDB-server-5.5.49-1.el7.centos.x86_64
MariaDB-common-5.5.49-1.el7.centos.x86_64
MariaDB-client-5.5.49-1.el7.centos.x86_64
卸载数据库:
[[email protected] rookie]# yum -y remove mari*
删除数据库文件:
[[email protected] rookie]# rm -rf /var/lib/mysql/*
2、官网下载安装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 |
3、安装完成之后重启mysqld服务
# service mysqld restart |
PS:初次安装mysql,root账户没有密码
4、配置MySQL
mysql配置文件为/etc/my.cnf
编码方式
最后加上编码配置
[mysql] default-character-set=utf8 |
这里的字符编码必须和/usr/share/mysql/charsets/Index.xml中一致。
设置密码
把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。
mysql> grant all privileges on *.* to [email protected]‘%‘identified by ‘abc123!‘; mysql> flush privileges; |
如果是新用户而不是root,则要先新建用户
mysql>create user ‘username‘@‘%‘ identified by ‘passwd‘; |