目录:导读

  • 一、前言
  • 二、安装mysql
  • 三、mysql重置密码
  • 四、查看mysql端口号
  • 五、授权mysql远程连接
  • 六、遇到问题

一、前言

Linux上安装软件常见的几种方式:

  • 源码编译
  • 压缩包解压(一般为tar.gz)
  • 编译好的安装包(RPM、DPKG等)
  • 在线安装(YUM、APT等)
    以上几种方式便捷性依次增加,但通用性依次下降

删除老版本MySQL的开发头文件和库

rm -rf  /etc/my.cnfrm -rf  /var/lib/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 ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)Active: active (running) since Tue 2019-01-15 09:53:42 CST; 47s agoMain 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/mysql

六、遇到问题

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

[root@yoyo ~]# systemctl status mysql.service
● mysqld.service - MySQL Community ServerLoaded: 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 agoProcess: 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服务器就解决了

软件测试搭建环境--在Linux安装MySQL(详细),精细整理相关推荐

  1. Linux安装mysql详细步骤

    linux安装mysql详细步骤 最近买了个腾讯云服务器,搭建环境. 该笔记用于系统上未装过mysql的干净系统第一次安装mysql.自己指定安装目录,指定数据文件目录. linux系统版本: Cen ...

  2. Linux 安装Mysql 详细教程(图文教程)

    首先通过 xshell 或者 putty 远程进入Linux 命令行操作界面. Xshell 的安装 1.去 XShell - Download 下载需要的版本. XShell免费版(解决官网打不开的 ...

  3. Linux 安装Mysql 详细教程

    mysql安装包 1.安装包下载地址 MySQL :: Download MySQL Community Server (Archived Versions) 2.选择对应的包 如下5.7包 下载和安 ...

  4. linux安装mysql详细过程【easy】

    1.看是否安装过 yum list installed | grep mysql 2.删除 yum -y remove mysql 3.安装 yum -y install mysql-server 4 ...

  5. linux 安装mysql 8.0_Linux安装mysql 8.0的详细方法介绍(代码示例)

    本篇文章给大家带来的内容是关于Linux安装mysql 8.0的详细方法介绍(代码示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 经过一番努力下载mysql文件,我们可以开始M ...

  6. 超详细Linux 安装Mysql

    超详细 Linux 安装Mysql 1.下载方式 1.1 Linux 内部下载(不推荐,比较慢) 1.2 本地下载,上传到linux 2.解压 3.创建MYSQL⽤户和⽤户组 4.配置my.cnf 5 ...

  7. Linux安装Mysql(图文解说详细版)

    安装前必看 这篇文章是用yum安装的,如果是官网安装包tar包安装请移步 Linux安装Mysql(图文解说详细版,安装包tar包版) 文章目录 安装前必看 最近开个新坑,就是在linux环境中操作开 ...

  8. Centos安装MySQL详细步骤(亲妈级教程)

    Centos安装MySQL详细步骤(亲妈级教程) {ubuntu安装mysql,其他linux安装MySQL同理} 0.下载 官网下载:MySQL 百度云下载: 链接:https://pan.baid ...

  9. 【树莓派】搭建LAMP(Linux Apache Mysql PHP)服务器

    基于树莓派搭建LAMP(Linux Apache Mysql PHP)服务器 配置树莓派 树莓派 连接WIFI 配置SSH 连接SSH 修改密码并解锁root用户 固定IP 调整服务器性能 Apach ...

最新文章

  1. 部署 instance 到 VXLAN - 每天5分钟玩转 OpenStack(112)
  2. .团队组建及项目启动
  3. ubuntu 上网总结
  4. boost::hana::slice_c用法的测试程序
  5. 福建省计算机初级职称,2019福建助理工程师职称评定条件材料及审核管理制度...
  6. java实体类生成mysql表_自己简单写的JDBCUtils,可以根据当前数据库下面的表生成java实体类。...
  7. Microsoft Access 查询
  8. 【20211005】Praat 基本用法
  9. 专注世界排名的Alexa.com宣布关站
  10. 激荡四十年,中国企业家群画像
  11. 多元相关性分析_NAR:宏基因组网络分析工具MetagenoNets
  12. Nginx的proxy_pass及upstream的小型负载均衡
  13. 从数码宝贝看spring bean的生命周期
  14. 移动魔百盒问题之我见
  15. 神经网络权重是什么意思,神经网络权重调整方法
  16. linux挂载多个虚拟光驱,Linux操作系统下虚拟光驱(iso)的挂载
  17. Linux内核源代码下载
  18. Robinson Crusoe chapter 8 A ship arrives at the island
  19. Github博客+腾讯云域名的快捷绑定方案
  20. inprivate浏览是什么意思_如何使IE浏览器打开默认是InPrivate浏览

热门文章

  1. Camera 面试总结
  2. 小米笔记本air13-3安装Deepin
  3. 盛大吸金“传奇”不再 陈天桥帝国梦碎
  4. 每日新闻:Gartner报告:这五大新兴科技趋势将模糊人机界限;阿里云肖力:阿里云安全三大“核驱动: 可信、智能、合规...
  5. 计算机无法访问iTunes,iPhone连接电脑后iTunes无响应怎么办【解决方法】
  6. 计算机中信息的表示与存储教案,计算机基础教案2--1.2信息的表示与存储.doc
  7. Redirected when going from “/index“ to “/xx“via a navigation guard
  8. Java数组之一维数值数组之成绩统计
  9. 关于mikefile 萌新用法
  10. XiaoHu日志 6/29~7/30