最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

CentOS下安裝MySQL5.6.10和安全配置教程詳解

 更新時(shí)間:2016年12月07日 11:12:37   作者:brishenzhou  
這篇文章主要介紹了CentOS下安裝MySQL5.6.10和安全配置教的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下

注:以下所有操作都在CentOS 6.5 x86_64位系統(tǒng)下完成。

#準(zhǔn)備工作#

在安裝MySQL之前,請(qǐng)確保已經(jīng)使用yum安裝了以下各類基礎(chǔ)組件(如果系統(tǒng)已自帶,還可以考慮yum update下基礎(chǔ)組件):

gcc
cmake
openssl+openssl-devel
pcre+pcre-devel
bzip2+bzip2-devel
libcurl+curl+curl-devel
libjpeg+libjpeg-devel
libpng+libpng-devel
freetype+freetype-devel
php-mcrypt+libmcrypt+libmcrypt-devel
libxslt+libxslt-devel
gmp+gmp-devel
libxml2+libxml2-devel
mhash
ncurses+ncurses-devel
xml2

然后創(chuàng)建mysql的用戶組和用戶,并且不允許登錄權(quán)限:

# id mysql
id: mysql:無(wú)此用戶
# groupadd mysql
# useradd -g mysql -s /sbin/nologin mysql
# id mysql
uid=500(mysql) gid=500(mysql) 組=500(mysql)

#MySQL的安裝#

給MySQL的安裝準(zhǔn)備目錄:

# mkdir -p /data/mysql/data
# chown -R mysql:mysql /data/mysql

開始源碼安裝MySQL:

# cd /usr/local/src
# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.10.tar.gz
# tar zxf mysql-5.6.10.tar.gz
# cd mysql-5.6.10
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.10 -DSYSCONFDIR=/usr/local/mysql-5.6.10/etc -DMYSQL_UNIX_ADDR=/usr/local/mysql-5.6.10/tmp/mysql.sock -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DMYSQL_DATADIR=/data/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1
...
CMake Warning:
Manually-specified variables were not used by the project:
MYSQL_USER
-- Build files have been written to: /usr/local/src/mysql-5.6.10
# make && make install
# mkdir -p /usr/local/mysql-5.6.10/etc
# mkdir -p /usr/local/mysql-5.6.10/tmp
# ln -s /usr/local/mysql-5.6.10/ /usr/local/mysql
# chown -R mysql:mysql /usr/local/mysql-5.6.10
# chown -R mysql:mysql /usr/local/mysql

給當(dāng)前環(huán)境添加MySQL的bin目錄:

# vim /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
$ source /etc/profile

執(zhí)行初初始化配置腳本并創(chuàng)建系統(tǒng)自帶的數(shù)據(jù)庫(kù)和表:

# cd /usr/local/mysql
# scripts/mysql_install_db --user=mysql --datadir=/data/mysql/data
...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h iZ94mobdenkZ password 'new-password'
Alternatively you can run:
./bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems with the ./bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
WARNING: Found existing config file ./my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as ./my-new.cnf,
please compare it with your file and take the changes you need.
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

注:由于MySQL在啟動(dòng)的時(shí)候,會(huì)先去/etc/my.cnf找配置文件,如果沒有找到則搜索$basedir/my.cnf,也即/usr/local/mysql-5.6.10/my.cnf,所以必須確保/etc/my.cnf沒有存在,否則可能導(dǎo)致無(wú)法啟動(dòng)。

實(shí)際操作上發(fā)現(xiàn)系統(tǒng)上存在該文件,所以這里可能需要將該文件先備份改名,然后再根據(jù)上面的配置寫配置文件:

# mv /etc/my.cnf /etc/my.cnf.bak
# vim /usr/local/mysql-5.6.10/my.cnf
[mysqld]
basedir=/usr/local/mysql-5.6.10
datadir=/data/mysql/data
socket=/usr/local/mysql-5.6.10/tmp/mysql.sock
user=mysql
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

修改MySQL用戶root的密碼,這里使用mysqld_safe安全模式啟動(dòng):

# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 3970
[root@iZ94mobdenkZ ~]# 141230 19:02:31 mysqld_safe Logging to '/data/mysql/data/centos.err'.
141230 19:02:32 mysqld_safe Starting mysqld daemon with databases from /data/mysql/data

這個(gè)時(shí)候已經(jīng)啟動(dòng)了mysqd_safe安全模式,另開一個(gè)窗口作為客戶端連入MySQL服務(wù)器:

# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.10 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql;
mysql> update user set password=password('yourpassword') where user='root';
mysql> flush privileges;
mysql> exit;

修改完畢之后使用kill把mysqld_safe進(jìn)程殺死:

# ps aux | grep mysql
root 3970 0.0 0.2 106308 1492 pts/1 S 19:02 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking
mysql 4143 0.1 18.0 558280 90316 pts/1 Sl 19:02 0:00 /usr/local/mysql-5.6.10/bin/mysqld --basedir=/usr/local/mysql-5.6.10 --datadir=/data/mysql/data --plugin-dir=/usr/local/mysql-5.6.10/lib/plugin --user=mysql --skip-grant-tables --skip-networking --log-error=/data/mysql/data/centos.err --pid-file=/data/mysql/data/centos.pid --socket=/usr/local/mysql-5.6.10/tmp/mysql.sock
root 4313 0.0 0.1 103252 836 pts/0 S+ 19:05 0:00 grep mysql
# kill -9 3970
# kill -9 4143

或者回到剛才啟動(dòng)mysqld_safe的窗口ctrl+c將進(jìn)程殺死也行。

復(fù)制服務(wù)啟動(dòng)腳本:

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld

設(shè)置開機(jī)啟動(dòng)MySQL服務(wù)并正常開啟MySQL服務(wù)(非必要項(xiàng)):

# chkconfig mysqld on
# service mysqld
Usage: mysqld {start|stop|restart|reload|force-reload|status} [ MySQL server options ]
# service mysqld start
Starting MySQL.

以后就可以直接通過(guò)service mysqld命令來(lái)開啟/關(guān)閉MySQL數(shù)據(jù)庫(kù)了。

最后,建議生產(chǎn)環(huán)境下運(yùn)行安全設(shè)置腳本,禁止root用戶遠(yuǎn)程連接,移除test數(shù)據(jù)庫(kù)和匿名用戶等:

# /usr/local/mysql-5.6.10/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):

注:上面輸入的root密碼指的是前面設(shè)置的MySQL的root賬戶的密碼。

至此,MySQL數(shù)據(jù)庫(kù)已經(jīng)安裝完畢。

#MySQL的安全配置#

1、確保啟動(dòng)MySQL不能使用系統(tǒng)的root賬號(hào),必須是新建的mysql賬號(hào),比如:

# mysqld_safe --user=mysql

2、MySQL安裝好運(yùn)行初始化數(shù)據(jù)庫(kù)后,默認(rèn)的root賬戶密碼為空,必須給其設(shè)置一個(gè)密碼,同時(shí)保證該密碼具有較高的安全性。比如:

mysql> user mysql;
mysql> update user set password=password('yourpassword') where user='root';
mysql> flush privileges;

3、刪除默認(rèn)數(shù)據(jù)庫(kù)及用戶:

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
mysql> drop daabase test;
mysql> use mysql;
mysql> select host,user from user;
+--------------+------+
| host | user |
+--------------+------+
| 127.0.0.1 | root |
| ::1 | root |
| centos | |
| centos | root |
| localhost | |
| localhost | root |
+--------------+------+
mysql> delete from user where not(host='localhost' and user='root');
mysql> flush privileges;

注:上面的user表中的數(shù)據(jù)可能會(huì)有所不同。

4、當(dāng)開發(fā)網(wǎng)站連接數(shù)據(jù)庫(kù)的時(shí)候,建議建立一個(gè)用戶只針對(duì)某個(gè)庫(kù)有update/select/delete/insert/drop table/create table等權(quán)限,減小某個(gè)項(xiàng)目的數(shù)據(jù)庫(kù)的用戶名和密碼被竊取后造成其他項(xiàng)目受影響,比如:

mysql>create database yourdbname default charset utf8 collate utf8_general_ci;
mysql>create user 'yourusername'@'localhost' identified by 'yourpassword';
mysql> grant select,insert,update,delete,create,drop privileges on yourdbname.* To 'yourusername'@localhost identified by 'yourpassword';

5、數(shù)據(jù)庫(kù)文件所在的目錄不允許未經(jīng)授權(quán)的用戶訪問(wèn),需要控制對(duì)該目錄的訪問(wèn),比如:

# chown -R mysql:mysql /data/mysql/data
# chmod -R go-rwx /data/mysql/data

以上所述是小編給大家介紹的CentOS下安裝MySQL5.6.10和安全配置教程詳解,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Windows下mysql5.7.10安裝配置方法圖文教程

    Windows下mysql5.7.10安裝配置方法圖文教程

    這篇文章主要為大家詳細(xì)介紹了Windows上mysql5.7.10安裝配置方法圖文教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • MySQL如何生成唯一的server-id

    MySQL如何生成唯一的server-id

    這篇文章主要給大家介紹了關(guān)于MySQL如何生成唯一的server-id的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用MySQL具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • mysql使用insert into select插入查出的數(shù)據(jù)

    mysql使用insert into select插入查出的數(shù)據(jù)

    這篇文章主要介紹了mysql使用insert into select插入查出的數(shù)據(jù)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • MySQL中字段類型為longtext的值導(dǎo)出后顯示二進(jìn)制串方式

    MySQL中字段類型為longtext的值導(dǎo)出后顯示二進(jìn)制串方式

    這篇文章主要介紹了MySQL中字段類型為longtext的值導(dǎo)出后顯示二進(jìn)制串方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • Windows下通過(guò)MySQL Installer安裝MySQL服務(wù)的教程圖解

    Windows下通過(guò)MySQL Installer安裝MySQL服務(wù)的教程圖解

    MYSQL官方提供了Installer方式安裝MYSQL服務(wù)以及其他組件,使的Windows下安裝,卸載,配置MYSQL變得特別簡(jiǎn)單。接下來(lái)通過(guò)圖文并茂的形式給大家介紹Windows下通過(guò)MySQL Installer安裝MySQL服務(wù)的教程,一起看看吧
    2018-10-10
  • MySQL安裝三種方法總結(jié)(yum安裝、編譯安裝、二進(jìn)制安裝)

    MySQL安裝三種方法總結(jié)(yum安裝、編譯安裝、二進(jìn)制安裝)

    MySQL安裝網(wǎng)上的教程有很多,基本上大同小異,但是安裝軟件有時(shí)就可能因?yàn)橐粋€(gè)細(xì)節(jié)安裝失敗,這篇文章主要介紹了MySQL安裝三種方法的相關(guān)資料,三種方法分別是yum安裝、編譯安裝以及二進(jìn)制安裝,需要的朋友可以參考下
    2023-12-12
  • MYSQL出現(xiàn)" Client does not support authentication "的解決方法

    MYSQL出現(xiàn)" Client does not support authentication "的

    MYSQL出現(xiàn)" Client does not support authentication "的解決方法...
    2007-06-06
  • MySQL深分頁(yè)優(yōu)化方式

    MySQL深分頁(yè)優(yōu)化方式

    本文討論了MySQL中深分頁(yè)問(wèn)題及其解決方法,包括延遲關(guān)聯(lián)和最大ID查詢法,延遲關(guān)聯(lián)通過(guò)兩步查詢優(yōu)化性能,減少數(shù)據(jù)掃描量和IO操作,充分利用索引,最大ID查詢法利用數(shù)據(jù)表中ID的有序性,減少掃描量和IO操作,性能提升明顯,但依賴有序ID、不適合復(fù)雜排序需求
    2024-12-12
  • MySQL Innodb行格式詳解

    MySQL Innodb行格式詳解

    在數(shù)據(jù)庫(kù)管理中,行格式是數(shù)據(jù)存儲(chǔ)的重要概念,尤其是在MySQL的InnoDB存儲(chǔ)引擎中,本文給大家介紹MySQL Innodb行格式,感興趣的朋友跟隨小編一起看看吧
    2024-09-09
  • MySQL中CASE?WHEN語(yǔ)句用法、示例與解析舉例

    MySQL中CASE?WHEN語(yǔ)句用法、示例與解析舉例

    這篇文章主要給大家介紹了關(guān)于MySQL中CASE?WHEN語(yǔ)句用法、示例與解析的相關(guān)資料,case when語(yǔ)句用于計(jì)算條件列表并返回多個(gè)可能結(jié)果表達(dá)式之一,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-05-05

最新評(píng)論

永登县| 凤城市| 垦利县| 同心县| 富民县| 黑山县| 左云县| 民权县| 沂水县| 阜康市| 杨浦区| 贵港市| 延川县| 张家港市| 天水市| 宁阳县| 佛山市| 九寨沟县| 宁安市| 沧州市| 通辽市| 绥滨县| 洮南市| 沭阳县| 武邑县| 五常市| 枣强县| 株洲县| 隆安县| 林甸县| 德令哈市| 江都市| 浦东新区| 专栏| 沙田区| 平利县| 汶川县| 齐河县| 宽甸| 拉萨市| 温州市|