centos7 ssh安装mysql_centos7安装mysql5.7

我打算在我的centos7.2上面装一个mysql5.7,我选择编译安装

1 要安装,首先要有安装包,下载去

因为mysql5.7要求boost,所以建议大家尽量选择自带boost的mysql源码包下载来安装,这样就不用麻烦单独安装boost了.我下载的是mysql-boost-5.7.18.tar.gz

[root@python ~]# ll mysql-boost-5.7.18.tar.gz

-rw-r--r--. 1 root root 61612105 11月  9 2017 mysql-boost-5.7.18.tar.gz

2 检查系统有没有安装mysql和boost

[root@python ~]# rpm -qa | grep boost

[root@python ~]# rpm -qa | grep mysql

3 安装mysql所需的一些依赖包

[root@python ~]# yum -y install make gcc-c++ cmake bison-devel  ncurses-devel   bison perl perl-devel perl perl-devel

...........................作为依赖被升级:

libdb.x86_64 0:5.3.21-20.el7

libdb-utils.x86_64 0:5.3.21-20.el7

libstdc++.x86_64 0:4.8.5-16.el7

完毕!

4 安装了依赖包,就可以开始安装我们的mysql了.

1) 创建mysql用户和组

为了安全起见,mysql用户不登录,而且mysql作为系统服务,指定mysql用户的群组为mysql群组

[root@python ~]# groupadd mysql;useradd -r -g mysql -s /bin/false mysql

useradd 的-r参数是创建系统账号,-g指定用户所属组为mysql,-s /bin/false 指定用户的shell为禁止login,其实这里还可以设置为/sbin/nologin.

/bin/false是最严格的禁止login选项,一切服务都不能用。

/sbin/nologin只是不允许login系统.

当用户配置成/sbin/nologin时,如果再使用该用户ssh到linux操作系统,会提示#This account is currently not available.

当用户配置成/bin/false时,用户不能登录,使用ssh之后不会有任何提示,用户切换不过去.

2) 创建数据目录

[root@python ~]# mkdir -p /data/mysql/data

3) 解压包

[root@python ~]# tar -zxvf mysql-boost-5.7.18.tar.gz

.........................

4) 编译

[root@python mysql-5.7.18]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost;make;make install

.......................

哎,因为我是用渣配置的虚拟机,编译搞去我一个多小时.

编译安装完成以后,下面我们开始为使用做准备

5) 初始化

把mysql安装目录的所属用户和组改成mysql

[root@python mysql-5.7.18]# cd /usr/local/mysql

[root@python mysql]# pwd

/usr/local/mysql

[root@python mysql]# chown -R mysql .

[root@python mysql]# chgrp -R mysql .

[root@python mysql]#

做好了上面的,就开始初始化了,因为生产环境中,经常会要求开启ssl功能,我这里初始化就开启了

[root@python mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data

2017-11-10T11:41:27.358625Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2017-11-10T11:41:29.728684Z 0 [Warning] InnoDB: New log files created, LSN=45790

2017-11-10T11:41:30.113932Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2017-11-10T11:41:30.796879Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 18512606-c60c-11e7-b780-000c294e66bd.

2017-11-10T11:41:30.924616Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2017-11-10T11:41:30.929250Z 1 [Note] A temporary password is generated for root@localhost: gDqqGu8uer+a

6) 把mysql添加到系统服务

[root@python mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[root@python mysql]# chmod a+x /etc/init.d/mysqld

[root@python mysql]#

7) 替换配置文件:

[root@python support-files]# cp /etc/my.cnf /etc/my.cnf.bak

[root@python support-files]# cp my-default.cnf /etc/my.cnf

my.cnf      my.cnf.bak  my.cnf.d/

[root@python support-files]# cp my-default.cnf /etc/my.cnf

cp:是否覆盖"/etc/my.cnf"? y

[root@python support-files]#

8) 赋予权限:

[root@python sys]# chown -R mysql.mysql /data/mysql/

[root@python sys]# chown -R mysql.mysql /var/run/mysql/

[root@python sys]# chown -R mysql.mysql /var/lib/mysql/

[root@python sys]# chown -R mysql.mysql /var/log/mysql/

[root@python sys]# chown -R mysql.mysql /data/mysql/

9) 启动mysql:

[root@python sys]# service mysqld start

Starting MySQL.Logging to '/var/log/mysql/mysql.log'.

. SUCCESS!

10) 连接到mysql:

[root@python bin]# mysql -u root -p

Enter password:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

这是由于我们连接数据库使用的主机名参数为“localhost”,或者未使用主机名参数、服务器默认使用“localhost”做为主机名。 使用主机名参数为“localhost”连接mysql服务端时,mysql客户端会认为是连接本机,所以会尝试以socket文件方式进行连接(socket文件连接方式,比“ip:端口”方式效率更高),这时根据配置文件“/etc/mysql.cnf”的路径,未找到相应的socket文件,就会引发此错误。

所以需要让mysql的客户端能找到scoket文件,这个参数在my.cnf文件里面配置

[root@python bin]# vi /etc/my.cnf

# For advice on how to change settings please see

..............................................

[client]

socket = /var/lib/mysql/mysql.sock

[mysql]

socket = /var/lib/mysql/mysql.sock

添加配置后,重启mysql

[root@python bin]# mysql -uroot -p

Enter password:

.................................

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

OK,我的mysql装好了.

下一次装python用的mysqldb

PS:个人之见,如果有错误的地方,欢迎大家指正

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值