博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
centos7安装mysql5.6
阅读量:4627 次
发布时间:2019-06-09

本文共 4876 字,大约阅读时间需要 16 分钟。

CentOS7上安装mysql5.6

(最好切换到root下操作!)

  1. CentOS7将默认数据库由mysql替换为Mariadb,因此需要先卸载Mariadb。方法为:
[root@gerrit+gitlab ~]# rpm -qa|grep mariadbmariadb-libs-5.5.60-1.el7_5.x86_64[root@gerrit+gitlab ~]# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
  1. 删除my.conf:(如果存在的话)
[root@gerrit+gitlab ~]# rm /etc/my.cnf
  1. 创建mysql用户组:
[root@gerrit+gitlab ~]# groupadd mysql
  1. 创建mysql用户并加入用户组:
[root@gerrit+gitlab ~]# useradd -g mysql mysql
  1. 下载安装包:

从 https://dev.mysql.com/downloads/mysql/5.6.html#downloads下载mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz,适配操作系统选择Linux - Generic (glibc 2.12) (x86, 64-bit), Compressed TAR Archive版本的。

拷贝到/usr/local目录并解压:

[root@gerrit+gitlab local]# tar -zxvf mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz

然后重命名文件夹为mysql:

[root@gerrit+gitlab local]# mv mysql-5.6.42-linux-glibc2.12-x86_64 mysql
  1. /etc目录下新建my.cnf(或者从/usr/local/mysql/support-files将my-default.cnf拷贝过来并改名为my.cnf),内容修改为:
[mysql]# 设置mysql客户端默认字符集default-character-set=utf8socket=/var/lib/mysql/mysql.sock[mysqld]skip-name-resolve#设置3306端口port = 3306socket=/var/lib/mysql/mysql.sock# 设置mysql的安装目录basedir=/usr/local/mysql# 设置mysql数据库的数据的存放目录datadir=/usr/local/mysql/data# 允许最大连接数max_connections=200# 服务端使用的字符集默认为8比特编码的latin1字符集character-set-server=utf8# 创建新表时将使用的默认存储引擎default-storage-engine=INNODBlower_case_table_name=1max_allowed_packet=16M
  1. 安装:
[root@gerrit+gitlab ~]# cd /usr/local/mysql/[root@gerrit+gitlab mysql]# chown -R mysql:mysql ./[root@gerrit+gitlab mysql]# mkdir data[root@gerrit+gitlab mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

如果提示:FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:

Data::Dumper

那就:

[root@gerrit+gitlab mysql]# yum install autoconf -y

然后重新执行前一句安装命令即可。

完成后修改权限:

 

[root@gerrit+gitlab mysql]# chown -R mysql:mysql data
  1. 配置:

授予my.cnf最大权限:

[root@gerrit+gitlab ~]# chmod 777 /etc/my.cnf

设置开机自启动:

[root@gerrit+gitlab mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld

并增加权限:

[root@gerrit+gitlab mysql]# chmod +x /etc/rc.d/init.d/mysqld

将mysqld加入到系统服务:

[root@gerrit+gitlab mysql]# chkconfig --add mysqld

检查一下:

[root@gerrit+gitlab mysql]# chkconfig --list mysqld      Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration.       If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'.      mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
  1. 启动:
[root@gerrit+gitlab mysql]# service mysqld startWarning: World-writable config file '/etc/my.cnf' is ignoredStarting MySQL.Warning: World-writable config file '/etc/my.cnf' is ignoredWarning: World-writable config file '/etc/my.cnf' is ignoredLogging to '/usr/local/mysql/data/gerrit+gitlab.err'.. SUCCESS!

上面的Warning提示是说my.cnf全局可写,不安全,那就修改一下:

[root@gerrit+gitlab mysql]# chmod 644 /etc/my.cnf

现在可以再试试service mysqld stop和service mysqld start了:

[root@gerrit+gitlab mysql]# service mysqld stopShutting down MySQL.. SUCCESS![root@gerrit+gitlab mysql]# service mysqld startStarting MySQL.190105 21:21:32 mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists. ERROR! The server quit without updating PID file (/usr/local/mysql/data/gerrit+gitlab.pid).

出现ERROR,解决方法如下:

[root@gerrit+gitlab mysql]# mkdir -p /var/run/mysqld[root@gerrit+gitlab mysql]# chown mysql:mysql /var/run/mysqld/[root@gerrit+gitlab mysql]# mv /etc/my.cnf /etc/my.cnf.bk[root@gerrit+gitlab mysql]# service mysqld startStarting MySQL. SUCCESS!

编辑~/.bash_profile,最后面增加:

export PATH=$PATH:/usr/local/mysql/bin

并立即生效:

[root@gerrit+gitlab mysql]# source ~/.bash_profile

现在就登录并设置root密码(初始密码为空,直接回车)和远程访问用户名密码吧:

[root@gerrit+gitlab mysql]# mysql -uroot -pEnter password:Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.42 MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>

设置root的密码为root:

mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> update user set password=password('root') where user='root' and host='localhost';Query OK, 1 row affected (0.01 sec)Rows matched: 1  Changed: 1  Warnings: 0mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql>

设置远程访问用户名为zjd,密码为zjdpass:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'zjd'@'%' IDENTIFIED BY 'zjdpass' WITH GRANT OPTION;Query OK, 0 rows affected (0.00 sec)mysql>

      

转载于:https://www.cnblogs.com/zjd1396/p/10227459.html

你可能感兴趣的文章
如何屏蔽国内IP访问我们的网站的一些方法!
查看>>
起与伏
查看>>
ExtJS遮罩层Ext.loadMask
查看>>
ArcPy开发教程2-管理地图文档1
查看>>
过滤器的使用
查看>>
软件测试
查看>>
Response.Status http协议状态代码
查看>>
BZOJ4925 城市规划
查看>>
Bootstrap 辅助类
查看>>
TCP、UDP、HTTP、SOCKET之间的区别
查看>>
根据Buffer中的图片数据进行图片呈现的方法.
查看>>
用Python编写WordCount程序任务
查看>>
AC日记——传纸条 洛谷 P1006
查看>>
Android Gradle 多Module单独编译一个Module
查看>>
React显示文件夹中SVG
查看>>
编码规范小结
查看>>
695. Max Area of Island
查看>>
(转)Cortex-M3 (NXP LPC1788)之SDRAM操作
查看>>
201671010437 王小倩+词频统计软件项目报告
查看>>
python中的变量,字符串,用户交互,if语句
查看>>