mysql 5.7.14 安装配置代码分享
本文记录了mysql5.7.14安装配置代码,具体内容如下
OS:CentOS6.6
DB:Mysql5.7.14
1.下载mysql
cd/tools
wgethttp://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
2.创建MySQL二进制解压文件的目录
mkdir-p/opt/mysql [root@zw-test-dbmysql]#cd/tools/ [root@zw-test-dbtools]#ll-lmysql-5.7.14-linux-glibc2.5-x86_64.tar.gz -rw-r--r--1rootroot642694570Aug2915:02mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
3.解压到/opt/mysql目录下
[root@zw-test-dbtools]#cd/opt/mysql/ [root@zw-test-dbmysql]#tar-zxvf/tools/mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz [root@zw-test-dbmysql]#mvmysql-5.7.14-linux-glibc2.5-x86_64/mysql-5.7.14 [root@zw-test-dbmysql]#ll drwxr-xr-x97161314154096Jul1221:03mysql-5.7.14
4.创建一个软连接到/usr/local
[root@zw-test-dbmysql]#cd/usr/local/ [root@zw-test-dblocal]#ls binetcgamesincludeliblib64libexecredis-3.2.2sbinsharesrc [root@zw-test-dblocal]#ln-s/opt/mysql/mysql-5.7.14/usr/local/mysql [root@zw-test-dblocal]#llmysql lrwxrwxrwx1rootroot23Aug3117:36mysql->/opt/mysql/mysql-5.7.14 [root@zw-test-dblocal]#
5.创建用户
[root@zw-test-db/]#groupaddmysql [root@zw-test-db/]#useradd-M-gmysql-s/sbin/nologin-d/usr/local/mysqlmysql
-s nologin没有shell不能登录的
6.基于配置文件创建基本的目录
mkdir/data/mysql mkdir/data/mysql/mysql_3306 cd/data/mysql/mysql_3306/ mkdirdata mkdirlogs mkdirtmp chown-Rmysql:mysql/data/mysql/mysql3306
7.创建/etc/my.cnf配置文件(过程略)
8.初始化,5.7的初始化会加一个默认的密码
[root@zw-test-dbmysql]#cd/usr/local/mysql/ [root@zw-test-dbmysql]#./bin/mysqld--initialize [root@zw-test-dbdata]#pwd /data/mysql/mysql_3306/data ###下面是5.5,5.6初始化 /usr/local/mysql/scripts/mysql_install_db--user=mysql--basedir=/usr/local/mysql
9.查看error日志,看有没有error
cd/data/mysql/mysql_3306/data [root@zw-test-dbdata]#vimerror.log [root@zw-test-dbdata]#tail-ferror.log 2016-08-31T09:44:32.394657Z0[Note]Giving0clientthreadsachancetodiegracefully 2016-08-31T09:44:32.394680Z0[Note]Shuttingdownslavethreads 2016-08-31T09:44:32.394686Z0[Note]Forcefullydisconnecting0remainingclients 2016-08-31T09:44:32.415409Z0[Note]Binlogend 2016-08-31T09:44:32.434217Z0[Note]InnoDB:FTSoptimizethreadexiting. 2016-08-31T09:44:32.434293Z0[Note]InnoDB:Startingshutdown... 2016-08-31T09:44:32.534587Z0[Note]InnoDB:Dumpingbufferpool(s)to/data/mysql/mysql_3306/data/ib_buffer_pool 2016-08-31T09:44:32.534741Z0[Note]InnoDB:Bufferpool(s)dumpcompletedat16083117:44:32 2016-08-31T09:44:34.308784Z0[Note]InnoDB:Shutdowncompleted;logsequencenumber2525428 2016-08-31T09:44:34.308945Z0[Note]InnoDB:Removedtemporarytablespacedatafile:"ibtmp1"
10.查看初始化密码
[root@zw-test-dbdata]#greppassworderror.log
2016-08-31T09:44:21.172167Z1[Note]Atemporarypasswordisgeneratedforroot@localhost:8aahkRkxfm%t
密码是:8aahkRkxfm%t
11创建一个启动脚本
[root@zw-test-dbdata]#cd/usr/local/mysql/
[root@zw-test-dbmysql]#cpsupport-files/mysql.server/etc/init.d/mysql
cp:overwrite`/etc/init.d/mysql'?y
12.启动mysql的三种方式
方式一:
root@zw-test-dbbin]#./mysqld_safe--user=mysql& [1]12455 [root@zw-test-dbbin]#16083015:18:01mysqld_safeLoggingto'/usr/local/mysql/data/zw-test-db.err'. 16083015:18:01mysqld_safeStartingmysqlddaemonwithdatabasesfrom/usr/local/mysql/data
方式二:
[root@zw-test-dbbin]#/etc/init.d/mysqldrestart ShuttingdownMySQL..16083015:18:14mysqld_safemysqldfrompidfile/usr/local/mysql/data/zw-test-db.pidended [OK] StartingMySQL.[OK] [1]+Done./mysqld_safe--user=mysql
方式三:
[root@zw-test-dbbin]#servicemysqldrestart ShuttingdownMySQL..[OK] StartingMySQL.[OK] [root@zw-test-dbbin]#
13.添加环境变量
echo"exportPATH=\$PATH:/usr/local/mysql/bin">>/root/.bash_profile
source/root/.bash_profile
14.登陆
[root@zw-test-dbmysql]#mysql-uroot-p Enterpassword: WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnectionidis3 Serverversion:5.7.14-log Copyright(c)2000,2016,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. root@localhost[(none)]>showdatabases;--提示要修改密码 ERROR1820(HY000):YoumustresetyourpasswordusingALTERUSERstatementbeforeexecutingthisstatement.
15.修改密码
root@localhost[(none)]>alteruseruser()identifiedby'123456'; QueryOK,0rowsaffected(0.00sec) mysql>flushprivileges; QueryOK,0rowsaffected(0.00sec) root@localhost[(none)]>showdatabases; +--------------------+ |Database| +--------------------+ |information_schema| |mysql| |performance_schema| |sys| +--------------------+ 4rowsinset(0.00sec)
可以查看数据库了
16.5.6版本之前需要帐号安全加固,5,7以后test数据库都没有了
deletefrommysql.userwhereuser!='root'orhost!='localhost';--删除非root用户,登陆主机不是localhost的账号 flushprivileges; alteruseruser()identifiedby'123456'; dropdatabasetest; truncatemysql.db;
精彩专题分享:mysql不同版本安装教程mysql5.7各版本安装教程
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。