方法一:安装mariadb
centos7 版本将MySQL数据库软件从默认程序列表移除,用mariadb代替。
1. # yum install mariadb-server mariadb (注:安装mariadb)
mariadb数据库的相关命令是:
systemctl start mariadb #启动MariaDB
systemctl stop mariadb #停止MariaDB
systemctl restart mariadb #重启MariaDB
systemctl enable mariadb #设置开机启动
2. # systemctl start mariadb(注:启动数据库)
方法二:官网下载安装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 - 设置密码 mysql> set password for 'root'@'localhost' =password('password');
配置MySQL
mysql配置文件为/etc/my.cnf
最后加上编码配置
[mysql]
default-character-set =utf8
字符编码需要与/usr/share/mysql/charsets/Index.xml中一致
远程连接设置
把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。
mysql> grant all privileges on . to root@'%'identified by 'password';
如果是新用户而不是root,则要先新建用户
mysql>create user 'username'@'%' identified by 'password';