Centos 7 可安装 mysql5.7

卸载mysql
yum remove mysqlhtml

 

使用yum安装MySQL(CentOS 6.2):mysql

 第一次先安装repositorylinux

http://dev.mysql.com/doc/refman/5.6/en/linux-installation-yum-repo.html#yum-repo-setupsql

 

mkdir /home/tools

mkdir /home/tools/mysql数据库

cd /home/tools/mysql

wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm安全

//wget http://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm服务器

sudo yum localinstall mysql57-community-release-el7-11.noarch.rpmsocket

sudo yum install mysql-community-server

四、启动测试

    4.一、启动服务:this

    service mysqld start 

    4.二、开机启动

    chkconfig --levels 235 mysqld on

    

五、配置

 

在/etc/my.cnf中添加 

validate-password=OFF

否则简单密码将不能被mysql接受

    5.一、MySQL安全安装

    执行下面的命令:

    /usr/bin/mysql_secure_installation

    涉及内容包括:

    设置或更改root密码 ( 初次安装,初始密码:grep 'temporary password' /var/log/mysqld.log)

    移除匿名用户

    禁止远程登陆root

    删除测试数据库test

    从新加载受权表

    

******** 完成上面的步骤,即成功完成安装

 

常见异常

 

Mysql:is not allowed to connect to this MySQL server

若是你想链接你的mysql的时候发生这个错误:
ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL server

解决方法:
1。 改表法。多是你的账号不容许从远程登录,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"

mysql -u root -pvmware

mysql>use mysql;

mysql>update user set host = '%' where user = 'root';

//刷新系统权限表
mysql>flush privileges;

mysql>select host, user from user;

2. 受权法。例如,你想myuser使用mypassword从任何主机链接到mysql服务器的话。
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
若是你想容许用户myuser从ip为192.168.1.3的主机链接到mysql服务器,并使用mypassword做为密码
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123ABCabc' WITH GRANT OPTION;

 

 

 

 重置密码方法

 

 可尝试这样启动  mysqld_safe -skip-grant-tables

 

或者

在/etc/my.ini的[mysqld]字段加入:
skip-grant-tables
重启mysql服务,这时的mysql不须要密码便可登陆数据库
而后进入mysql
mysql>use mysql;
mysql>update user set password=password('新密码') WHERE User='root';
mysql>flush privileges;
运行以后最后去掉my.ini中的skip-grant-tables,重启mysqld便可。
5.7 中用:update user set authentication_string=password('123ABCabc') WHERE User='root';
ALTER USER USER() IDENTIFIED BY password('123ABCabc');
 
 

You must reset your password using ALTER USER statement before executing this statement

经过"skip-grant-tables"配置,客户端链接 ,修改 user 表的字段 password_expired 为  'N';

 

 

六、自定义MySQL数据文件目录

    有时须要自定义MySQL的数据文件夹,即datadir;

    6.一、创建目标目录,这里假定为 /home/data/mysql;    

 

service mysqld stop

mkdir /home/data

mv /var/lib/mysql /home/data/

mkdir /home/data/mysql/log/

touch mysqld.log

    

 

    6.二、受权目录读写权限给MySQL的运行用户,上面安装后的MySQL会以用户mysql运行,则受权语句以下: 

chown -R mysql:mysql /home/data/mysql

    6.三、修改/etc/my.cnf文件,[mysqld]增长datadir、socket配置,[client]也须要增长socket配置

            [mysqld]

            datadir=/home/data/mysql

            socket=/home/data/mysql/mysql.sock

            [client]

            socket=/home/data/mysql/mysql.sock

 

mysql 5.7配置 示例

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
port=3307
server_id=1
character-set-server=utf8mb4
datadir=/home/data/mysql
socket=/home/data/mysql/mysql.sock
validate-password=OFF
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/home/data/mysql/log/mysqld.log
pid-file=/home/data/mysql/mysqld.pid
 
[client]
socket=/home/data/mysql/mysql.sock

 

 

 

            

    6.四、若是启动失败,可经过cat /var/log/mysqld.log 查看启动日志,若是出现以下错误,则是因为SELINUX限制引发

        InnoDB: Operating system error number 13 in a file operation.

        InnoDB: The error means mysqld does not have the access rights to

        InnoDB: the directory.

        解决方法: chcon -Rt mysqld_db_t /home/data/mysql

七、

1、Warning: World-writable config file '/etc/my.cnf' is ignored

To fix this problem, use the following command to change file’s permissions

要修改该问题,使用如下命令更改该文件的权限。

 

chmod 644 /etc/my.cnf

 四、找到my.cnf配置文件 
   若是/etc/目录下没有my.cnf配置文件,请到/usr/share/mysql/下找到*.cnf文件,拷贝其中一个到/etc/并更名为my.cnf)中。命令以下: 
   [root@test1 mysql]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf 

相关文章
相关标签/搜索