CentOS7安装mysql5.7解压缩版简明教程
本文实例讲述了CentOS7安装mysql5.7解压缩版的方法。分享给大家供大家参考,具体如下:
1.下载安装包
http://dev.mysql.com/downloads/mysql/#downloads
推荐下载通用安装方法的TAR包
2.检查库文件是否存在,如有删除。
[root@localhostDesktop]$rpm-qa|grepmysql mysql-libs-5.1.52-1.el6_0.1.x86_64 [root@localhost~]$rpm-emysql-libs-5.1.52.x86_64--nodeps [root@localhost~]$
3.检查mysql组和用户是否存在,如无创建。
[root@localhost~]$cat/etc/group|grepmysql mysql:x:490: [root@localhost~]$cat/etc/passwd|grepmysql mysql:x:496:490::/home/mysql:/bin/bash 以上为默认存在的情况,如无,执行添加命令: [root@localhost~]$groupaddmysql [root@localhost~]$useradd-r-gmysqlmysql //useradd-r参数表示mysql用户是系统用户,不可用于登录系统。
4.解压TAR包,更改所属的组和用户
[root@localhost~]$cd/usr/local/ [root@localhostlocal]$tarxvfmysql-5.7.12-linux-glibc2.5-x86_64.tar [root@localhostlocal]$ls-l total1306432 -rwxr--r--.1rootroot668866560Jun115:07mysql-5.7.12-linux-glibc2.5-x86_64.tar -rw-r--r--.17161wheel638960236Mar2812:54mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz -rw-r--r--.17161wheel29903372Mar2812:48mysql-test-5.7.12-linux-glibc2.5-x86_64.tar.gz [root@localhostlocal]$tarxvfzmysql-5.7.12-linux-glibc2.5-x86_64.tar.gz [root@localhostlocal]$mvmysql-5.7.12-linux-glibc2.5-x86_64mysql [root@localhostlocal]$ls-l total1306436 drwxr-xr-x.2rootroot4096Dec42009bin drwxr-xr-x.2rootroot4096Dec42009etc drwxr-xr-x.2rootroot4096Dec42009games drwxr-xr-x.2rootroot4096Dec42009include drwxr-xr-x.2rootroot4096Dec42009lib drwxr-xr-x.3rootroot4096Dec214:36lib64 drwxr-xr-x.2rootroot4096Dec42009libexec drwxr-xr-x.97161wheel4096Mar2812:51mysql -rwxr--r--.1rootroot668866560Jun115:07mysql-5.7.12-linux-glibc2.5-x86_64.tar -rw-r--r--.17161wheel638960236Mar2812:54mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz -rw-r--r--.17161wheel29903372Mar2812:48mysql-test-5.7.12-linux-glibc2.5-x86_64.tar.gz drwxr-xr-x.2rootroot4096Dec42009sbin drwxr-xr-x.6rootroot4096Dec214:36share drwxr-xr-x.2rootroot4096Dec42009src [root@localhostlocal]$chown-Rmysqlmysql/ [root@localhostlocal]$chgrp-Rmysqlmysql/ [root@localhostlocal]$cdmysql/
5.安装和初始化数据库
[root@localhostmysql]$bin/mysql_install_db--user=mysql--basedir=/usr/local/mysql/--datadir=/usr/local/mysql/data/ 2016-06-0115:23:25[WARNING]mysql_install_dbisdeprecated.Pleaseconsiderswitchingtomysqld--initialize 2016-06-0115:23:30[WARNING]Thebootstraplogisn'tempty: 2016-06-0115:23:30[WARNING]2016-06-01T22:23:25.491840Z0[Warning]--bootstrapisdeprecated.Pleaseconsiderusing--initializeinstead 2016-06-01T22:23:25.492256Z0[Warning]Changedlimits:max_open_files:1024(requested5000) 2016-06-01T22:23:25.492260Z0[Warning]Changedlimits:table_open_cache:431(requested2000)
如果改变默认安装路径,则需要 1)/etc/my.cnf、/etc/init.d/mysqld中修改 basedir='/apps/mysql' datadir='/apps/mysql/data' 2)创建ln mkdir-p/usr/local/mysql/bin ln-s/apps/mysql/bin/mysqld/usr/local/mysql/bin/mysqld
[root@localhostmysql]$ [root@localhostmysql]$cp-a./support-files/my-default.cnf/etc/my.cnf [root@localhostmysql]$cp-a./support-files/mysql.server/etc/init.d/mysqld [root@localhostmysql]$cdbin/ [root@localhostbin]#./mysqld_safe--user=mysql& [1]2932 [root@localhostbin]#2016-06-01T22:27:09.708557Zmysqld_safeLoggingto'/usr/local/mysql/data/localhost.localdomain.err'. 2016-06-01T22:27:09.854913Zmysqld_safeStartingmysqlddaemonwithdatabasesfrom/usr/local/mysql/data [root@localhostbin]#/etc/init.d/mysqldrestart ShuttingdownMySQL..2016-06-01T22:27:50.498694Zmysqld_safemysqldfrompidfile/usr/local/mysql/data/localhost.localdomain.pidended SUCCESS! StartingMySQL.SUCCESS! [1]+Done./mysqld_safe--user=mysql [root@localhostbin]$ //设置开机启动 [root@localhostbin]$chkconfig--level35mysqldon [root@localhostbin]$
6.初始化密码
mysql5.7会生成一个初始化密码,而在之前的版本首次登陆不需要登录。
[root@localhostbin]$cat/root/.mysql_secret #Passwordsetforuser'root@localhost'at2016-06-0115:23:25 ,xxxxxR5H9 [root@localhostbin]$./mysql-uroot-p Enterpassword: WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnectionidis2 Serverversion:5.7.12 Copyright(c)2000,2016,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. mysql>SETPASSWORD=PASSWORD('123456'); QueryOK,0rowsaffected,1warning(0.00sec) mysql>flushprivileges; QueryOK,0rowsaffected(0.00sec)
7.添加远程访问权限
mysql>usemysql; Readingtableinformationforcompletionoftableandcolumnnames Youcanturnoffthisfeaturetogetaquickerstartupwith-A Databasechanged mysql>updateusersethost='%'whereuser='root'; QueryOK,1rowaffected(0.00sec) Rowsmatched:1Changed:1Warnings:0 mysql>selecthost,userfromuser; +-----------+-----------+ |host|user| +-----------+-----------+ |%|root| |localhost|mysql.sys| +-----------+-----------+ //一定要重启才会生效。 /etc/init.d/mysqldrestart
遇到的问题:
找不到mysql.sock,mysql.sock丢失问题解决方法
连接Mysql时,机器上找不到mysql.sock文件你可以简单地通过重启服务器重新创建得到它。因为服务器在启动时重新创建它。
[root@localhostmysql-5.7.13]#./bin/mysql_install_db--user=mysql 2016-06-2602:47:09[WARNING]mysql_install_dbisdeprecated.Pleaseconsiderswitchingtomysqld--initialize 2016-06-2602:47:09[ERROR]Thedatadirectoryneedstobespecified.
解决:需要新建data目录,指定安装目录(在非默认目录时需要指定,默认路径:/usr/local/mysql,同时需要指定./support-files/mysql.server中的basedir和datadir为相应路径)。
[root@localhostmysql-5.7.13]#./bin/mysql_install_db--user=mysql--basedir=/usr/local/mysql-5.7.13/--datadir=/usr/local/mysql-5.7.13/data/ 2016-06-2602:48:47[WARNING]mysql_install_dbisdeprecated.Pleaseconsiderswitchingtomysqld--initialize 2016-06-2602:49:19[WARNING]Thebootstraplogisn'tempty: 2016-06-2602:49:19[WARNING]2016-06-26T09:48:50.798592Z0[Warning]--bootstrapisdeprecated.Pleaseconsiderusing--initializeinstead 2016-06-26T09:48:50.898732Z0[Warning]Changedlimits:max_open_files:1024(requested5000) 2016-06-26T09:48:50.898778Z0[Warning]Changedlimits:table_open_cache:431(requested2000)
以上报错均因未在mysql.server中指定自定义的路径。
若是还提示已经有data文件了删除了它,新建即可
希望本文所述对大家CentOS服务器维护有所帮助。