centos7搭建lnmp安装二进制mysql【三】

1.官网下载安装包 mysql-5.6.25-linux-glibc2.5-x86_64.tar.gz

2.通过命令解压文件
[ root@localhost share]# tar -zxvf mysql-5.6.25-linux-glibc2.5-x86_64.tar.gz 

3.重命名文件,并放到合适位置
[ root@localhost share]# mv mysql-5.6.25-linux-glibc2.5-x86_64 /usr/local/mysql

4.进入/usr/local/mysql目录,进行下列操作
a. 增加用户组mysql
[ root@localhost mysql]# groupadd mysql
b.增加用户mysql到用户组mysql
[ root@localhost mysql]# useradd -g mysql mysql
c.改变当前文件目录拥有者和拥有的用户组
[ root@localhost mysql]#   chown -R mysql:mysql /usr/local/mysql
注:这一步可以防止除了mysql用户和root用户,其他用户都无法修改这个文件下的内容

5.初始化数据库实例
[ root@localhost mysql]# scripts/mysql_install_db --user=mysql

6.放启动文件和配置文件
[ root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[ root@localhost mysql]# cp my.cnf  /etc/my.cnf

7.调用mysqld_safe启动mysql服务,并放入后台执行
[ root@localhost mysql]# bin/mysqld_safe --usr=mysql &

8.查看是否已经启动
[ root@localhost mysql]# netstat -ntlp | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      16546/mysqld   

注:

netstat -t参数:t代表TCP协议的套节字链接,除了t之外还有u(UDP)、w(RAW)、x(UNIX)套节字。

netstat -a参数:a就是(all)简写,意思就是包括全部正在监听的端口。

netstat -n参数:直接显示端口号,不是根据“/etc/server”显示端口对应的服务名称。

netstat -p参数:显示占用该端口号的进程。

netstat -l参数:显示正在被监听的端口。



9.登录mysql
[ root@localhost mysql]# bin/mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.25 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> 
10.安装成功
注:如果遇到 MySQL server through socket '/tmp/mysql.sock',请看centos是否安装了数据库,把相关的数据库卸载了;比如mariadb
============================

其他后期设置
1.修改用户密码:
方案1.直接进入数据库mysql更新user表中root的密码
mysql> use mysql
mysql> update user set password=PASSWORD('root') where user='root';
mysql> flush privileges;

方案2.赋予root所有权限,并修改密码为root
mysql> grant all privileges on *.* to root@'%' IDENTIFIED BY 'root';
注:root@'%'表示可以从任何地方访问该库,即可远程访问; IDENTIFIED BY后面跟的是用户密码,即访问密码;如果为root@'localhost' 表示该用户只能在本地访问该库

2.把mysql的bin路径加入环境变量PATH中:
[ root@localhost mysql]# vim /etc/profile
进入编辑后,在最后添加
export PATH="/usr/local/mysql/bin:$PATH"
立即生效
[ root@localhost mysql]# source /etc/profile

3.设置mysql自动运行
[ root@localhost ~]# chkconfig --add mysqld
[ root@localhost ~]# chkconfig --level 345 mysqld on
[ root@localhost ~]# chkconfig --list | grep mysqld

注:
   --add  增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据。
   --del  删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的叙述文件内删除相关数据。
   --level<等级代号>  指定读系统服务要在哪一个执行等级中开启或关毕。
      等级0表示:表示关机
      等级1表示:单用户模式
      等级2表示:无网络连接的多用户命令行模式
      等级3表示:有网络连接的多用户命令行模式
      等级4表示:不可用
      等级5表示:带图形界面的多用户模式
      等级6表示:重新启动


4.如果需要测试远程能不能连接上,可以先禁止掉防火墙
[ root@localhost ~]# systemctl stop firewalld.service
或者如下
[ root@localhost ~]# iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

查看
[ root@localhost ~]# iptables -L -n|grep 3306
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:3306
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:3306

======================
MySQL远程连接丢失问题解决方法,Mysql错误Lost connection to MySQL server at ‘reading initial communication packet’, system error: 0解决方法,需要的朋友可以参考下

系统请根据情况自行找到my.cnf的路径。一般只会存放在/etc/my.cnf或者/etc/mysql/my.cnf下。
首先用vim打开my.cnf:

复制代码 代码如下:

vim /etc/mysql/my.cnf

看看是否有绑定本地回环地址的配置,如果有,注释掉下面这段文字:(在文字之前加上#号即可)

复制代码 代码如下:

bind-address = 127.0.0.1

然后找到[mysqld]部分的参数,在配置后面建立一个新行,添加下面这个参数:
skip-name-resolve
保存文件并重启MySQL:

复制代码 代码如下:
/etc/init.d/mysql restart





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值