linux系统安装mysql

      我们以CentOS6为例来安装mysql。

第一步:Linux环境

       首先大家新建一个虚拟机,配置静态IP并且要能上网。

第二步:安装wget命令

[root@taotao-mysql ~]# yum install -y wget
第三步:创建存放所有安装文件的目录

             我一般习惯于把所有安装文件都放到/usr/local/software目录下,但是software是没有的,因此我们需要创建它。

[root@taotao-mysql ~]# mkdir /usr/local/software
第四步:进入到/usr/local/software

[root@taotao-mysql ~]# cd /usr/local/software/
第五步:下载mysql安装文件

[root@taotao-mysql software]# wget http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
 第六步:安装仓库列表

[root@taotao-mysql software]# yum localinstall mysql-community-release-el6-5.noarch.rpm
第七步:安装mysql

[root@taotao-mysql software]# yum install -y mysql-community-server
第八步:启动mysql

[root@taotao-mysql software]# service mysqld start
第九步:设置root用户密码

        mysql数据库安装完以后只会有一个root管理员账号,但是此时的root账号还并没有为其设置密码,在第一次启动mysql服务时,会进行数据库的一些初始化工作,在输出的一大串信息中,我们看到有如下这样一行信息

[root@taotao-mysql software]# /usr/bin/mysqladmin -u root password 'new-password'

        我们就用这条命令来修改mysql密码

[root@taotao-mysql software]# /usr/bin/mysqladmin -u root password 'root'

        如果不设置远程授权的话,那么将无法从别的设备登录到该mysql上。如下信息是我从cmd命令窗口尝试远程连接mysql,结果提示不允许访问

C:\Users\dell16>mysql -h 192.168.156.41 -P 3306 -uroot -p
Enter password: ****
ERROR 1130 (HY000): Host '192.168.156.100' is not allowed to connect to this MySQL server

第十步:mysql远程连接授权

       这一步要求我们先登录mysql

[root@taotao-mysql software]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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 'root' WITH GRANT OPTION;
Query OK, 0 rows affected (0.03 sec)

mysql>
         登录mysql后,我们再执行如下所示命令

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
第十一步:测试远程连接

        linux服务器的mysql端口为3306,默认情况下防火墙是开着的,我们把防火墙关掉。

[root@taotao-mysql software]# service iptables stop
iptables:将链设置为政策 ACCEPT:filter                    [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:                                   [确定]
[root@taotao-mysql software]# chkconfig iptables off
[root@taotao-mysql software]# reboot
        重启服务器,然后在windows系统的cmd窗口中使用如下命令来访问服务器上的mysql,如下所示。

C:\Users\dell16>mysql -h 192.168.156.41 -P 3306 -uroot -p
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值