前言

在linux上安装mysql5.6版本,并远程连接mysql数据库操作

安装mysql

mysql的安装可以用yum安装更方便

[root@yoyo ~]# cd /usr/local/

[root@yoyo ~]# mkdir mysql-community-release

[root@yoyo ~]# cd mysql-community-release

[root@yoyo ~]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

[root@yoyo ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm

[root@yoyo ~]# yum -y install mysql-community-server

安装完成后查看版本号:mysql -V

[root@yoyo local]# mysql -V

mysql Ver 14.14 Distrib 5.6.42, for Linux (x86_64) using EditLine wrapper

安装完成后重启mysql服务,查看状态是 Active: active (running) ,说明启动成功

启动服务:service mysqld restart

[root@yoyo local]# service mysqld restart

查看mysql运行状态:systemctl status mysql.service

[root@yoyo local]# systemctl status mysql.service

[root@yoyo local]# service mysqld restart

Redirecting to /bin/systemctl restart mysqld.service

Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.

[root@yoyo ~]# systemctl status mysql.service

● mysqld.service - MySQL Community Server

Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)

Active: active (running) since Tue 2019-01-15 09:53:42 CST; 47s ago

Main PID: 946 (mysqld_safe)

CGroup: /system.slice/mysqld.service

├─ 946 /bin/sh /usr/bin/mysqld_safe --basedir=/usr

└─1282 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/v...

Jan 15 09:53:39 yoyo systemd[1]: Starting MySQL Community Server...

Jan 15 09:53:40 yoyo mysqld_safe[946]: 190115 09:53:40 mysqld_safe Logging to '/var/log/mysqld.log'.

Jan 15 09:53:40 yoyo mysqld_safe[946]: 190115 09:53:40 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

Jan 15 09:53:42 yoyo systemd[1]: Started MySQL Community Server.

mysql重置密码

方法一:

初次安装使用mysql,root账户默认是没设置密码的,系统会给个临时密码,在/var/log/mysqld.log可以查看

[root@yoyo local]# grep 'temporary password' /var/log/mysqld.log

如下图所示,出现的就是临时密码,复制出来就可以登录mysql了

[root@yoyo local]# mysql -u root -p

看到Enter password: 输入密码,重置密码后exit退出mysql

[root@yoyo local]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 26

Server 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 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> update user set password = Password('root') where User = 'root';

# 回车后执行(刷新MySQL系统权限相关的表):

mysql> flush privileges;

# 再执行exit退出:

mysql> exit;

Bye

[root@yoyo local]#

方法二:

要是上一步找不到临时密码,那就用此方法,先停掉mysql,以安全方式启动

[root@yoyo local]# systemctl stop mysql.service

以安全方式启动mysql:

[root@yoyo local]# /usr/bin/mysqld_safe --skip-grant-tables >/dev/null 2>&1 &

然后执行

[root@yoyo local]# /usr/bin/mysql -u root mysql

出现“mysql>”提示符后输入:

mysql> update user set password = Password('root') where User = 'root';

回车后执行(刷新MySQL系统权限相关的表):

mysql> flush privileges;

再执行exit退出:

mysql> exit;

退出后,使用以下命令登陆mysql,试试是否成功:

[root@yoyo local]#mysql -u root -p

按提示输入密码:root

[root@yoyo local]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 27

Server 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 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>

出现Welcome to the MySQL那就是登录成功了

查看mysql端口号

mysql默认端口是3306,如何查看msyql端口号呢?可以用root账号登录后,执行show variables like 'port';

[root@yoyo local]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 33

Server 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 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> show variables like 'port';

+---------------+-------+

| Variable_name | Value |

+---------------+-------+

| port | 3306 |

+---------------+-------+

1 row in set (0.00 sec)

mysql>

授权mysql远程连接

mysql在linux上安装完成后,为了方便的查看,可以在本地电脑上安装一个远程连接数据库的客户端,远程连上mysql

方法一:

先创建一个root新用户,登录密码为password,可以自己随便命名

mysql> create user 'root'@'%' identified by 'password';

[root@yoyo sysconfig]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

mysql> create user 'root'@'%' identified by 'password';

ERROR 1396 (HY000): Operation CREATE USER failed for 'root'@'%'

mysql> exit

方法二:

查看user表,把host为localhost,user为root的记录更新host为%就是允许远程访问了

操作mysql时候,先执行use mysql

[root@yoyo sysconfig]# mysql -u root -p

Enter password:

mysql> use mysql

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

\Database changed

mysql> select user,host,password from user;

+-------+-----------+-------------------------------------------+

| user | host | password |

+-------+-----------+-------------------------------------------+

| root | yoyo | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |

| root | 127.0.0.1 | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |

| root | ::1 | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |

| | yoyo | |

| root1 | % | *668425423DB5193AF921380129F465A6425216D0 |

| root | localhost | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |

+-------+-----------+-------------------------------------------+

6 rows in set (0.00 sec)

如果看到root后面的host对应的是%说明有远程访问权限,显示localhost就 update更新它,如何flush privileges刷新系统权限

mysql> use mysql

mysql> update user set host = '%' where user = 'root';

ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> select user,host,password from user;

+-------+-----------+-------------------------------------------+

| user | host | password |

+-------+-----------+-------------------------------------------+

| root | yoyo | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |

| root | 127.0.0.1 | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |

| root | ::1 | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |

| | yoyo | |

| root1 | % | *668425423DB5193AF921380129F465A6425216D0 |

| root | % | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |

+-------+-----------+-------------------------------------------+

6 rows in set (0.00 sec)

mysql> exit

方法三:

授权法,给root用户远程登录的权限

# 想root使用123456从任何主机连接到mysql服务器的话

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123546' WITH GRANT OPTION;

# 如果你想允许用户root从ip为192.168.1.3的主机连接到mysql服务器,并使用123456作为密码

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY '123456' WITH GRANT OPTION;

接下来去阿里云ECS服务后台安全组-添加规则,新增3306端口访问权限,使用Navicat远程工具就可以连上了

这里的账号密码就是前面方法一里面设置的“root” 和“password”

开启与关闭服务

1启动mysql

service mysqld start

2查看mysql运行状态

service mysqld status # 或者 systemctl status mysql.service

3停掉mysql服务

service mysqld stop # 或者 systemctl stop mysql.service

4重启mysql

systemctl restart mysql.service

5查看运行进程

ps -ef | grep mysqld

[root@yoyo sysconfig]# ps -ef | grep mysql

mysql 2506 1 0 12:51 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr

mysql 2674 2506 0 12:51 ? 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock

root 2748 1668 0 12:55 pts/0 00:00:00 grep --color=auto mysql

6查看mysql端口

netstat -tulpn |grep mysql

[root@yoyo sysconfig]# netstat -tulpn |grep mysql

tcp6 0 0 :::3306 :::* LISTEN 2674/mysqld

遇到问题

启动mysql的时候,出现Failed to start MySQL Community Server.具体报错如下

[root@yoyo ~]# systemctl status mysql.service

● mysqld.service - MySQL Community Server

Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)

Active: failed (Result: start-limit) since Mon 2019-01-14 20:31:27 CST; 13h ago

Process: 26800 ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=0/SUCCESS)

Process: 26799 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=1/FAILURE)

Process: 26786 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)

Main PID: 26799 (code=exited, status=1/FAILURE)

Jan 14 20:31:27 yoyo systemd[1]: Failed to start MySQL Community Server.

Jan 14 20:31:27 yoyo systemd[1]: Unit mysqld.service entered failed state.

Jan 14 20:31:27 yoyo systemd[1]: mysqld.service failed.

Jan 14 20:31:27 yoyo systemd[1]: mysqld.service holdoff time over, scheduling restart.

Jan 14 20:31:27 yoyo systemd[1]: start request repeated too quickly for mysqld.service

Jan 14 20:31:27 yoyo systemd[1]: Failed to start MySQL Community Server.

Jan 14 20:31:27 yoyo systemd[1]: Unit mysqld.service entered failed state.

Jan 14 20:31:27 yoyo systemd[1]: mysqld.service failed.

刚开始以为是哪里配置有问题,后来百度搜了下,reboot重启linux服务器就解决了。

交流QQ群:779429633

centos 安装mysql5.6.20_Linux学习15-CentOS安装mysql5.6环境相关推荐

  1. centos7安装mysql5.7.16_Linux学习三Centos7安装mysql5.7.16数据库的详细教程

    这篇文章主要为大家详细介绍了Linux学习第三篇,Centos7安装mysql5.7.16数据库,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 如果您有服务器咨询问题.购买问题.可以联系我们客服 ...

  2. linux系统下安装qgis,深度操作系统 deepin 15.11安装 QGIS 3.4

    深度操作系统是基于Linux内核,以桌面应用为主的开源 GNU/Linux 操作系统,支持笔记本.台式机和一体机.深度操作系统(deepin)包含深度桌面环境(DDE)和近30款深度原创应用,及数款来 ...

  3. mysql64位机安装和配置_MySQL学习第二天 安装和配置mysql winx64

    一.安装方式 MySQL安装文件分为两种,一种是MSI格式的,一种是ZIP格式的.下面来看看这两种方式: MSI格式的可以直接点击安装,按照它给出的安装提示进行安装,Windows操作系统下一般MyS ...

  4. linux编译安装的好处,Linux学习—源码安装

    源码安装--可以按照自己的需求安装,这是源码安装的好处,而二进制安装无法选择 大部分的源码安装步骤大致相同,具体细节可以参考解压缩之后的README和INSTALL README: 介绍了软件包的功能 ...

  5. centos 安装Jitsi架设_Docker学习6:docker安装centos7

    docker安装centos7 一.查看可用的centos版本信息 1.Centos镜像库 CentOS镜像库地址:https://hub.docker.com/_/centos?tab=tags&a ...

  6. centos 重装 php5,centos6.6学习笔记:安装PHP5.5

    更新源 rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm rpm -Uvh https:/ ...

  7. centos rpm安装mysql5.5_CentOS下以RPM方式安装MySQL5.5

    首先去mySQL官网下载页面: http://dev.mysql.com/downloads/mysql/#downloads Select Platform 选择  Oracle & Red ...

  8. centos tar安装mysql_centos系统通过tar.gz包安装mysql5.7.19

    系统:centos6.5    64位系统 1.下载mysql 本人选的linux generic 通用版 64位 2.把mysql传到服务器并解压到/usr/local tar -xzvf mysq ...

  9. Linux学习之CentOS(十三)--CentOS6.4下Mysql数据库的安装与配置

    如果要在Linux上做j2ee开发,首先得搭建好j2ee的开发环境,包括了jdk.tomcat.eclipse的安装(这个在之前的一篇随笔中已经有详细讲解了Linux学习之CentOS(七)--Cen ...

最新文章

  1. CorelDRAW快捷键搜集
  2. oracle 19c补丁下载,rpm 安装oracle 19c,通过补丁升级到19.8
  3. dwr和ajax的区别,dwr的ajax实现
  4. windows传真和扫描由于不能访问您的文档_扫描识别工具Dynamic Web TWAIN全年最低价来了!错过再等一年...
  5. supervisor 子进程退出_用supervisor监管你的程序,不用担心程序挂了
  6. 微课|《Python编程基础与案例集锦(中学版)》第3章例题讲解(2)
  7. videojs 动态加载视频
  8. 设置Eclipse自带Ant指定版本JDK和运行时参数
  9. Leetcode Problem108
  10. 机器学习-马尔可夫随机场(MRF)
  11. android robotium测试,Android Robotium的几个小tips
  12. 学科前沿:基因启动子甲基化与宫颈癌发展的关系 | 文献科普
  13. 自动化生产线仿真教学
  14. 使用MD5加密的登陆demo
  15. 常用ES6语法归纳总结!
  16. 【毕业设计】43-基于单片机的红外无线防盗报警系统设计与实现(原理图工程源文件+源代码+实物图+答辩论文)
  17. LiveData的使用及详解
  18. win10的JDK安装环境变量配置
  19. 通过域名访问接口,报400
  20. 在小程序中显示地图并添加标注的教程

热门文章

  1. 开源公司 HashiCorp 国内险遭禁,阿里、华为也要做好 B 计划?
  2. 大部分程序员只会写三年代码?
  3. 面试者为何从来得不到反馈?
  4. 全方位解析阿里云核心技术竞争力,CSDN 独家在线峰会来了!
  5. 详解 TCP 连接的“ 三次握手 ”与“ 四次挥手 ”
  6. 为什么说没有物联网,就没有 AI ?
  7. 知乎“下沉”,快手“上游”
  8. 2019 世界读书日,让程序员疯狂的 13 本豆瓣高分技术书!
  9. 2018 腾讯功能游戏开发者赛事火热开启
  10. 马化腾:一推就倒!中国技术实力只是表面辉煌罢了