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 

相關文章
相關標籤/搜索