您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 其它行业文档 > Centos7下Mysql5.7详细安装步骤
Centos7下Mysql5.7详细安装步骤武深龙2018-5-14切记,mysql5.7以后默认是有初始化密码的,另外Centos7中关闭防火墙的命令与之前版本不大一样,本人在安装过程中此两处有些波折。1.首先查找Centos7是否默认安装mariadb,具体命令如下:#rpm-qa|grepmariadb2.如果存在mariadb,则执行如下命令进行卸载:#rpm-e--nodepsmariadb-libs-5.5.52-1.el7.x86_643.再次确认mariadb是否卸载干净,具体命令如下:#rpm-qa|grepmariadb4.创建mysql所在的用户组,具体命令如下:#groupaddmysql5.创建mysql所使用的用户,具体命令如下:#useradd-gmysqlmysql6.将mysql安装包拷贝到Centos7内,本文档默认拷贝到/wsl目录下,解压安装包命令如下:#tar-zxvf/wsl/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz7.在根目录下创建一个子目录work,命令如下:#mkdirwork8.将解压后的mysql目录移动至/work目录下并且改名为mysql,具体命令如下:#mv/wsl/mysql-5.7.22-linux-glibc2.12-x86_64/work/mysql9.修改mysql安装目录的权限,具体命令如下:#cd/work/mysql#chown-Rmysql.//此命令把当前目录下的文件及目录的属性修改为mysql用户#chgrp-Rmysql.//此命令把当前目录下的文件及目录所属组修改为mysql组10.创建data目录用于存放数据库文件,具体命令如下:#mkdirdata11.开始进行mysql系统初始化,执行命令大致如下:#/work/mysql/bin/mysqld--initialize--user=mysql--basedir=/work/mysql--datadir=/work/mysql/data执行上述命令的时候一定要注意,系统执行过程中回显内容大致如下:2018-05-14T01:12:57.186210Z0[Warning]TIMESTAMPwithimplicitDEFAULTvalueisdeprecated.Pleaseuse--explicit_defaults_for_timestampserveroption(seedocumentationformoredetails).2018-05-14T01:12:58.102507Z0[Warning]InnoDB:Newlogfilescreated,LSN=457902018-05-14T01:12:58.295969Z0[Warning]InnoDB:Creatingforeignkeyconstraintsystemtables.2018-05-14T01:12:58.370692Z0[Warning]NoexistingUUIDhasbeenfound,soweassumethatthisisthefirsttimethatthisserverhasbeenstarted.GeneratinganewUUID:f06157ca-5713-11e8-815a-080027324a9b.2018-05-14T01:12:58.374250Z0[Warning]Gtidtableisnotreadytobeused.Table'mysql.gtid_executed'cannotbeopened.2018-05-14T01:12:58.377082Z1[Note]Atemporarypasswordisgeneratedforroot@localhost:NWI%lIhk1(e其中最后的一串字符NWI%lIhk1(e为mysql初始化后的默认密码,这个密码一定要记住,否则后续操作将无法顺利进行,切记!12.第一次启动mysql,具体命令如下:#/work/mysql/bin/mysqld_safe--user=mysql&13.重新打开一个终端窗口或远程访问窗口,查看mysql是否成功启动,如果进程中有就证明启动成功,具体命令如下:#psaux|grepmysqld执行后返回结果大致如下:root151640.00.01132561612pts/0S09:170:00/bin/sh/work/mysql/bin/mysqld_safe--user=mysqlmysql152340.24.51119180178276pts/0Sl09:170:00/work/mysql/bin/mysqld--basedir=/work/mysql--datadir=/work/mysql/data--plugin-dir=/work/mysql/lib/plugin--user=mysql--log-error=localhost.localdomain.err--pid-file=localhost.localdomain.pidroot153280.00.0112664972pts/1R+09:190:00grep--color=automysqld14.修改mysql的默认密码,具体命令如下:#/work/mysql/bin/mysqladmin-uroot-ppasswordEnterpassword:Newpassword:Confirmnewpassword:Warning:Sincepasswordwillbesenttoserverinplaintext,usesslconnectiontoensurepasswordsafety.如果出现大致如上提示,证明密码修改成功。15.关闭mysql服务,具体命令如下:#/work/mysql/bin/mysqladmin-uroot-pshutdownEnterpassword:关闭服务要求输入密码,此处输入的是修改过的密码。16.验证mysql是否成功关闭,执行如下命令:#psaux|grepmysqlroot154620.00.0112664972pts/1R+09:250:00grep--color=automysql出现大致如上提示为mysql服务关闭成功。17.设置mysql为开机启动服务,首先将mysql.server文件拷贝到指定地点,具体命令如下:#cp/work/mysql/support-files/mysql.server/etc/rc.d/init.d/mysqld18.增加mysqld脚本的执行权限,具体命令如下:#chmod+x/etc/rc.d/init.d/mysqld19.将mysqld服务加入系统服务,具体命令如下:#chkconfig--addmysqld20.检查mysql服务是否生效,具体命令如下:#chkconfig--listmysqld21.修改mysqld文件的配置,具体命令如下:#vim/etc/rc.d/init.d/mysqld22.修改关键的两项信息如下:basedir=/work/mysqldatadir=/work/mysql/data23.执行启动命令如下:#servicemysqldstartStartingMySQL.SUCCESS!出现如提示则系统启动成功;24.设置允许远程登录,执行命令如下:#/work/mysql/bin/mysql-uroot-pEnterpassword:25.使用mysql库执行命令如下:mysqlusemysql;ReadingtableinformationforcompletionoftableandcolumnnamesYoucanturnoffthisfeaturetogetaquickerstartupwith-ADatabasechanged出现大致如上述提示则更换成功;26.执行允许远程以root用户访问命令,具体命令如下:mysqlGRANTALLPRIVILEGESON*.*TO'root'@'%'IDENTIFIEDBY'你更改后的密码'WITHGRANTOPTION;QueryOK,0rowsaffected,1warning(0.00sec)mysqlFLUSHPRIVILEGES;mysqlselectuser,hostfrommysql;ERROR1146(42S02):Table'mysql.mysql'doesn'texistmysqlselectuser,hostfromuser;+---------------+-----------+|user|host|+---------------+-----------+|root|%||mysql.session|localhost||mysql.sys|localhost||root|localhost|+---------------+-----------+4rowsinset(0.00sec)27.临时关闭Centos7防火墙执行命令大致如下:]#systemctlstopfirewalld28.禁止开机启动Centos7防火墙,执行命令大致如下:#systemctldisablefirewalld29.怀着激动的心情用客户端软件连接一下新安装的mysql5.7试试吧~
本文标题:Centos7下Mysql5.7详细安装步骤
链接地址:https://www.777doc.com/doc-4216597 .html