centos6.7 系统安装配置 mysql 数据库并配置远程访问

这里我们所说的安装 mysql 实际上是指安装 mysql-server ,就是mysql的服务端,mysql 客户端一般在 我们的系统里已经安装好了,并不需要再次安装了。不过我们也可以在安装 mysql-server 时重新安装 mysql 客户端

使用yum命令安装mysql

使用命令 yum list | grep mysql 查看 yum 上可用的 mysql 数据库版本。

yum list | grep mysql
yum list mysql-server

使用 yum install mysql-server 安装mysql服务端

➜  ~ yum install mysql-server

...此处省略一万字

总下载量:12 M
确定吗?[y/N]:y
下载软件包:
(1/5): mysql-5.1.73-7.el6.i686.rpm                | 904 kB     00:00     
(2/5): mysql-libs-5.1.73-7.el6.i686.rpm           | 1.2 MB     00:00     
(3/5): mysql-server-5.1.73-7.el6.i686.rpm         | 8.8 MB     00:00     
(4/5): perl-DBD-MySQL-4.013-3.el6.i686.rpm        | 134 kB     00:00     
(5/5): perl-DBI-1.609-4.el6.i686.rpm              | 705 kB     00:00     
-------------------------------------------------------------------------
总计                                      22 MB/s |  12 MB     00:00     
运行 rpm_check_debug 
执行事务测试
事务测试成功
执行事务
  正在升级   : mysql-libs-5.1.73-7.el6.i686                          1/6 
  正在安装   : perl-DBI-1.609-4.el6.i686                             2/6 
  正在安装   : perl-DBD-MySQL-4.013-3.el6.i686                       3/6 
  正在安装   : mysql-5.1.73-7.el6.i686                               4/6 
  正在安装   : mysql-server-5.1.73-7.el6.i686                        5/6 
  清理       : mysql-libs-5.1.73-5.el6_6.i686                        6/6 
  Verifying  : perl-DBD-MySQL-4.013-3.el6.i686                       1/6 
  Verifying  : mysql-server-5.1.73-7.el6.i686                        2/6 
  Verifying  : perl-DBI-1.609-4.el6.i686                             3/6 
  Verifying  : mysql-libs-5.1.73-7.el6.i686                          4/6 
  Verifying  : mysql-5.1.73-7.el6.i686                               5/6 
  Verifying  : mysql-libs-5.1.73-5.el6_6.i686                        6/6 

已安装:
  mysql-server.i686 0:5.1.73-7.el6                                       

作为依赖被安装:
  mysql.i686 0:5.1.73-7.el6        perl-DBD-MySQL.i686 0:4.013-3.el6     
  perl-DBI.i686 0:1.609-4.el6     

作为依赖被升级:
  mysql-libs.i686 0:5.1.73-7.el6                                         

完毕!

到这里就安装完成了

启动 mysql 服务

当我们第一次启动 mysql 数据库时,会进行一系列的初始化配置,输出如下内容

➜  ~ service mysqld start
Initializing MySQL database:  Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so,start the server,then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h VM_176_3_centos password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

这时, mysql 数据库就启动成功了,第二次启动数据库的时候 就不会再输出这么多内容了。

重启 mysql 数据库

重启数据库可以使用以下命令:

➜  ~ service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

设置开机自启

数据库启动成功后,设置 mysql 开机自启动

➜  ~ chkconfig mysqld on

可以通过 chkconfig --list | grep mysql 命令查看 mysql 数据库是否是开机自启动

➜  ~ chkconfig --list | grep mysql
mysqld             0:关闭    1:关闭    2:启用    3:启用    4:启用    5:启用    6:关闭

注意:chkconfig --list 可以查看服务器中 所有服务的自启动状态

设置 mysql 的密码

mysql数据库安装完以后只有一个root管理员账号,但是此时的root账号还没有为其设置密码,这时回头看一下在第一次启动mysql服务时,输出的一大段信息中,我们看到有这样一行信息 :

/usr/bin/mysqladmin -u root password 'new-password'  // 为root账号设置密码

所以我们可以通过 该命令来给我们的root账号设置密码(注意:这个root账号是mysql的root账号,非Linux的root账号)

➜  ~ mysqladmin -u root password '123456'  // 通过该命令给root账号设置密码为 123456

然后就可以通过 mysql -u root -p 命令来登录 mysql 数据库了

➜  ~ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.73 Source distribution

Copyright (c) 2000,2013,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 databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

mysql> exit;
Bye

查看安装好的 mysql-server 版本

使用rpm -qi mysql-server 命令查看安装好的 mysql-server 版本信息

➜  ~ rpm -qi mysql-server
Name        : mysql-server                 Relocations: (not relocatable)
Version     : 5.1.73                            Vendor: CentOS
Release     : 7.el6                         Build Date: 2016年05月11日 星期三 14时05分53秒
Install Date: 2016年10月08日 星期六 14时49分09秒      Build Host: worker1.bsys.centos.org
Group       : Applications/Databases        Source RPM: mysql-5.1.73-7.el6.src.rpm
Size        : 25688915                         License: GPLv2 with exceptions
Signature   : RSA/SHA1,2016年05月12日 星期四 18时46分25秒,Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://www.mysql.com
Summary     : The MySQL server and related files
Description :
MySQL is a multi-user,multi-threaded SQL database server. MySQL is a
client/server implementation consisting of a server daemon (mysqld)
and many different client programs and libraries. This package contains
the MySQL server and some accompanying files and directories.

卸载 mysql mysql-server

我们可以通过如下命令来查看我们的系统上是否 安装了 mysql

➜  ~ rpm -qa | grep mysql
mysql-5.1.73-7.el6.i686
mysql-libs-5.1.73-7.el6.i686
mysql-server-5.1.73-7.el6.i686

通过 rpm -e 命令 或者 rpm -e --nodeps 命令来卸载掉

➜  ~ rpm -qa | grep mysql
mysql-5.1.73-7.el6.i686
mysql-libs-5.1.73-7.el6.i686
mysql-server-5.1.73-7.el6.i686
➜  ~ rpm -e mysql  
error: Failed dependencies:
    mysql = 5.1.73-7.el6 is needed by (installed) mysql-server-5.1.73-7.el6.i686
➜  ~ rpm -e --nodeps mysql
➜  ~ rpm -qa | grep mysql 
mysql-libs-5.1.73-7.el6.i686
mysql-server-5.1.73-7.el6.i686

如上面的所示,当执行 rpm -e mysql 时会因为依赖关系 而出现错误,所以可以使用 rpm -e --nodeps mysql 来强制卸载,执行完之后 再查看安装的 mysql 发现少了 mysql-5.1.73-7.el6.i686
如果想全部卸载,再次执行

➜  ~ rpm -e --nodeps mysql-libs
➜  ~ rpm -e --nodeps mysql-server

即可。

mysql 的配置文件

mysql 的配置文件 保存在 /etc/my.cnf

我们可以看一下 内容:

➜  ~ cat /etc/my.cnf 
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

mysql 的数据库文件

mysql 的数据库文件存放路径为:/var/lib/mysql

➜  ~ ls -l /var/lib/mysql
总用量 20528
-rw-rw---- 1 mysql mysql 10485760 10月  8 15:11 ibdata1
-rw-rw---- 1 mysql mysql  5242880 10月  8 15:11 ib_logfile0
-rw-rw---- 1 mysql mysql  5242880 10月  8 14:50 ib_logfile1
drwx------ 2 mysql mysql     4096 10月  8 14:49 mysql
srwxrwxrwx 1 mysql mysql        0 10月  8 15:11 mysql.sock
drwx------ 2 mysql mysql     4096 10月  8 14:49 test

mysql 的日志输出文件

mysql数据库的日志输出存放位置在 /var/log 这个目录下

➜  ~ ls /var/log
anaconda.ifcfg.log    anaconda.yum.log  dmesg       messages    spooler
anaconda.log          audit             dmesg.old   mysqld.log  tallylog
anaconda.program.log  boot.log          dracut.log  ntpstats    wtmp
anaconda.storage.log  btmp              lastlog     prelink     yum.log
anaconda.syslog       cron              maillog     secure

其中mysqld.log 这个文件就是mysql数据库产生的一些日志信息,通过查看该日志文件,我们可以从中获得很多信息

查看监听端口

mysql 的服务端口为 3306 ,我们可以使用 netstat -anp 命令来查看系统是否在监听这个端口

➜  ~ netstat -anp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      3513/mysqld

设置 mysql 的远程访问

经过上面的设置后,还不能进行远程访问,连接的时候如下图所示:

解决办法

首先登录 mysql 数据库,然后使用命令grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option; 配置远程访问:

➜  ~ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.73 Source distribution

Copyright (c) 2000,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> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
Query OK,0 rows affected (0.00 sec)

mysql> exit;
Bye
➜  ~

再次测试,就OK了。

至此,所有的安装配置都完成了,如有纰漏,请及时告知,谢谢~~

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


linux下开机自启: 在/etc/init.d目录下新建文件elasticsearch 并敲入shell脚本: 注意, 前两行必须填写,且要注释掉。 第一行为shell前行代码,目的告诉系统使用shell。 第二行分别代表运行级别、启动优先权、关闭优先权,且后面添加开机服务会用到。 shell脚本
1、因为在centos7中/etc/rc.d/rc.local的权限被降低了,所以需要赋予其可执行权 chmod +x /etc/rc.d/rc.local 2、赋予脚本可执行权限假设/usr/local/script/autostart.sh是你的脚本路径,给予执行权限 chmod +x /usr
最简单的查看方法可以使用ls -ll、ls-lh命令进行查看,当使用ls -ll,会显示成字节大小,而ls- lh会以KB、MB等为单位进行显示,这样比较直观一些。 通过命令du -h –max-depth=1 *,可以查看当前目录下各文件、文件夹的大小,这个比较实用。 查询当前目录总大小可以使用d
ASP.NET Core应用程序发布linux在shell中运行是正常的。可一但shell关闭网站也就关闭了,所以要配置守护进程, 用的是Supervisor,本文主要记录配置的过程和过程遇到的问题 安装Supervisor&#160;1 yum install python-setuptools
设置时区(CentOS 7) 先执行命令timedatectl status|grep &#39;Time zone&#39;查看当前时区,如果不是时区(Asia/Shanghai),则需要先设置为中国时区,否则时区不同会存在时差。 #已经是Asia/Shanghai,则无需设置 [root@xia
vim&#160;/etc/sysconfig/network-scripts/ifcfg-eth0 BOOTPROTO=&quot;static&quot; ONBOOT=yes IPADDR=192.168.8.106 NETMASK=255.255.252.0 GATEWAY=192.168.
一、安装gcc依赖 由于 redis 是用 C 语言开发,安装之前必先确认是否安装 gcc 环境(gcc -v),如果没有安装,执行以下命令进行安装 [root@localhost local]# yum install -y gcc 二、下载并解压安装包 [root@localhost local
第一步 On CentOS/RHEL 6.*: $ sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el6/x86_64/nux-dextop-release-0-2.el6.nux.noarch.rpm On CentOS/RHEL 7: $
/// &lt;summary&gt; /// 取小写文件名后缀 /// &lt;/summary&gt; /// &lt;param name=&quot;name&quot;&gt;文件名&lt;/param&gt; /// &lt;returns&gt;返回小写后缀,不带“.”&lt;/ret
which nohup .bash_profile中并source加载 如果没有就安装吧 yum provides */nohup nohup npm run start &amp; nohup ./kibana &amp;
1.1 MySQL安装 1.1.1 下载wget命令 yum -y install wget 1.1.2 在线下载mysql安装包 wget https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm 1.1.3 安装My
重启 reboot shutdown -r now init 6 关闭 init 0 shutdown -h now shutdown -h 20:25 #8点25关机查看内存 free CPU利用率 top 日期 date 设置时间 date 033017002015 #月日时间年 日历 cal
1、firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status firewalld 开机禁用 : systemctl disable firewalld 开机启用 :
1 下载并安装MySQL官方的&#160;Yum Repository wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm 使用上面的命令就直接下载了安装用的Yum Repository,大概
CentOS6.x CentOS6中转用Upstrat代替以前的init.d/rcX.d的线性启动方式。 一、相关命令 通过initctl help可以查看相关命令 [root@localhost ~]# initctl help Job commands: start Start job. sto
1、使用命令:df -lk 找到已满磁盘 2、使用命令:du --max-depth=1 -h 查找大文件,删除
ifconfig:查看网卡信息 网卡配置文件位置: /etc/sysconfig/network-scripts/文件夹 nmtui:配置网卡 netstat -tlunp:查看端口信息 端口信息存储位置: /etc/services文件 route:查看路由信息 wget:下载网路文件,例如 wg
ps -ef:查看所有进程,&#160;ps -ef |grap firewalld 查看与firewalld相关的进程 which :查看进程:which firewalld kill 进程id:杀掉进程 kill 640,强制杀:kill -9 640 man:查看帮助,例如 man ps 查看
useradd:添加用户 useradd abc,默认添加一个abc组 vipw:查看系统中用户 groupadd:添加组groupadd ccna vigr:查看系统中的组 gpasswd:将用户abc添加到ccna组 gpasswd -a abc ccna groups abc:查看用户abc属