GVKun编程网logo

linux CentOS6.5 yum安装mysql 5.6

2

针对linuxCentOS6.5yum安装mysql5.6这个问题,本篇文章进行了详细的解答,同时本文还将给你拓展CentOS7.2Yum安装MySQL5.6、centosyum安装mysql、Cen

针对linux CentOS6.5 yum安装mysql 5.6这个问题,本篇文章进行了详细的解答,同时本文还将给你拓展CentOS 7.2 Yum安装MySQL 5.6、centos yum安装mysql、CentOS yum安装mysql&&jdk&&tomcat、centos6.0静态ip VMWare centos6.0静态ip设置等相关知识,希望可以帮助到你。

本文目录一览:

linux CentOS6.5 yum安装mysql 5.6

linux CentOS6.5 yum安装mysql 5.6

1.新开的云服务器,需要检测系统是否自带安装mysql

# yum list installed | grep mysql

2.如果发现有系统自带mysql,果断这么干

# yum -y remove mysql-libs.x86_64

3.随便在你存放文件的目录下执行,这里解释一下,由于这个mysql的yum源服务器在国外,所以下载速度会比较慢,还好mysql5.6只有79M大,而mysql5.7就有182M了,所以这是我不想安装mysql5.7的原因

# wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm

4.接着执行这句,解释一下,这个rpm还不是mysql的安装文件,只是两个yum源文件,执行后,在/etc/yum.repos.d/ 这个目录下多出mysql-community-source.repo和mysql-community.repo

# rpm -ivh mysql-community-release-el6-5.noarch.rpm

5.这个时候,可以用yum repolist mysql这个命令查看一下是否已经有mysql可安装文件

#yum repolist all | grep mysql

6.安装mysql 服务器命令(一路yes):

# yum install mysql-community-server

7.安装成功后

# service mysqld start

8.由于mysql刚刚安装完的时候,mysql的root用户的密码默认是空的,所以我们需要及时用mysql的root用户登录(第一次回车键,不用输入密码),并修改密码

# mysql -u root
# use mysql;
# update user set password=PASSWORD("这里输入root用户密码") where User=''root'';

9.创建一个utf8mb4编码的数据库

# create database databasename default character set utf8mb4 collate utf8mb4_unicode_ci; 

10.授权(自动创建)一个mysql的非root的aaa用户,能访问localhost上的testdb数据库,密码是xxxx,最后刷新权限

# grant all privileges on testdb.* to aaa@localhost identified by ''xxxx'';
# flush privileges;
# exit;

11.查看mysql是否自启动,并且设置开启自启动命令

# chkconfig --list | grep mysqld
# chkconfig mysqld on

12.mysql安全设置(系统会一路问你几个问题,看不懂复制之后翻译,基本上一路yes):

# mysql_secure_installation

13.安装完成推出

# exit

CentOS 7.2 Yum安装MySQL 5.6

CentOS 7.2 Yum安装MySQL 5.6

配置CentOS SCLo源

[3] 添加 CentOS SCLo Software collections Repository.
[root@linuxprobe~]# yum -y install centos-release-scl-rh centos-release-scl
# set [priority=10]
[root@linuxprobe~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo [root@linuxprobe~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
# for another way,change to [enabled=0] and use it only when needed
[root@linuxprobe~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo
[root@dlp ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo

yum安装MysqL

# 安装MysqL
[root@linuxprobe~]# yum --enablerepo=centos-sclo-rh -y install rh-MysqL56-MysqL-server
# 加载环境变量
[root@linuxprobe ~]# scl enable rh-MysqL56 bash
[root@linuxprobe ~]# MysqL -V 
MysqL  Ver 14.14 distrib 5.6.26,for Linux (x86_64) using  EditLine wrapper
[root@linuxprobe ~]# which MysqL 
/opt/rh/rh-MysqL56/root/usr/bin/MysqL
# 设置MysqL开机自启动
root@linuxprobe ~]# vi /etc/profile.d/rh-MysqL56.sh
#!/bin/bash
source /opt/rh/rh-MysqL56/enable
export X_SCLS="`scl enable rh-MysqL56 'echo $X_SCLS'`"
[4] Enable MysqL 5.6 and Configure initial settings.
[root@linuxprobe ~]# vi /etc/opt/rh/rh-MysqL56/my.cnf.d/MysqL-server.cnf
# add follows within [MysqLd] section
[MysqLd]
character-set-server=utf8
[root@linuxprobe ~]# systemctl start rh-MysqL56-MysqLd
[root@linuxprobe ~]# systemctl enable rh-MysqL56-MysqLd
[root@linuxprobe ~]# MysqL_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MysqL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MysqL to secure it,we'll need the current
password for the root user.  If you've just installed MysqL,and
you haven't set the root password yet,the password will be blank,so you should just press enter here.
Enter current password for root (enter for none):
OK,successfully used password,moving on...
Setting the root password ensures that nobody can log into the MysqL
root user without the proper authorisation.
# set root password
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default,a MysqL installation has an anonymous user,allowing anyone
to log into MysqL without having to have a user account created for
them.  This is intended only for testing,and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
# remove anonymous users
Remove anonymous users? [Y/n] y
 ... Success!
normally,root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
# disallow root login remotely
disallow root login remotely? [Y/n] y
 ... Success!
By default,MysqL comes with a database named 'test' that anyone can
access.  This is also intended only for testing,and should be removed
before moving into a production environment.
# remove test database
Remove test database and access to it? [Y/n] 
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
# reload privilege tables
Reload privilege tables Now? [Y/n] y
 ... Success!
Cleaning up...
All done!  If you've completed all of the above steps,your MysqL
installation should Now be secure.
Thanks for using MysqL!
[root@linuxprobe ~]# MysqL -u root -p
Enter password: 
Welcome to the MysqL monitor.  Commands end with ; or \g.
Your MysqL connection id is 13
Server version: 5.6.26 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> select user,host,password from MysqL.user; +------+-----------+-------------------------------------------+
| user | host | password | +------+-----------+-------------------------------------------+
| root | localhost | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 | | root | 127.0.0.1 | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 |
| root | ::1 | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 | +------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)
MysqL> show databases; +--------------------+
| Database | +--------------------+
| information_schema | | MysqL | | performance_schema |
+--------------------+
3 rows in set (0.00 sec)
MysqL> exit
Bye

开启防火墙
[root@linuxprobe ~]# firewall-cmd –add-service=MysqL –permanent
success
[root@linuxprobe ~]# firewall-cmd –reload
success

@H_184_301@
  • 同样使用yum在vdevops.org上面安装MysqL,安装步骤参考上面
  • MysqL 主从

    @H_184_301@
  • Master端:linuxprobe
  • [root@linuxprobe~]# vi /etc/opt/rh/rh-MysqL56/my.cnf.d/MysqL-server.cnf
    [MysqLd]
    # add follows in [MysqLd] section : get binary logs
    log-bin=MysqL-bin
    # define uniq server ID
    server-id=101
    [root@linuxprobe ~]# MysqL -u root -p 
    Enter password: 
    Welcome to the MysqL monitor.  Commands end with ; or \g.
    Your MysqL connection id is 2
    Server version: 5.6.26-log 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> grant replication slave on *.* to replica@'%' identified by 'password';
    Query OK,0 rows affected (0.07 sec)
    MysqL> flush privileges; 
    Query OK,0 rows affected (0.00 sec)
    MysqL> exit
    Bye

    开启防火墙
    [root@linuxprobe ~]# firewall-cmd –add-service=MysqL –permanent
    success
    [root@linuxprobe ~]# firewall-cmd –reload
    success

    @H_184_301@
  • Slave端:vdevops
  • [root@vdevops~]# vi /etc/opt/rh/rh-MysqL56/my.cnf.d/MysqL-server.cnf
    [MysqLd]
    # add follows in [MysqLd] section : get binary logs
    log-bin=MysqL-bin
    # define server ID (different one from Master Host)
    server-id=102
    # read only
    read_only=1
    # define own hostname
    report-host=node01.srv.world
    [root@vdevops~]# systemctl restart rh-MysqL56-MysqLd
    @H_184_301@
  • Master端:备份数据库
  • [root@linuxprobe ~]# MysqL -u root -p
    Enter password: 
    Welcome to the MysqL monitor.  Commands end with ; or \g.
    Your MysqL connection id is 3
    Server version: 5.6.26-log MysqL Community Server (GPL)
    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> flush tables with read lock;   # 锁表
    Query OK,0 rows affected (0.01 sec)
    MysqL> show master status;    #记住file的数值和position的值
    +------------------+----------+--------------+------------------+-------------------+
    | File             | Position | binlog_Do_DB | binlog_Ignore_DB | Executed_Gtid_Set |
    +------------------+----------+--------------+------------------+-------------------+
    | MysqL-bin.000001 |      400 |              |                  |                   |
    +------------------+----------+--------------+------------------+-------------------+
    1 row in set (0.00 sec)
    MysqL> exit
    Bye
    #
    [root@linuxprobe ~]# MysqLdump -u root -p --all-databases --lock-all-tables --events > MysqL_dump.sql # 备份数据库
    Enter password: 
    [root@linuxprobe ~]# MysqL -u root -p
    Enter password: 
    Welcome to the MysqL monitor.  Commands end with ; or \g.
    Your MysqL connection id is 5
    Server version: 5.6.26-log MysqL Community Server (GPL)
    
    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> unlock tables;  # 解锁
    Query OK,0 rows affected (0.00 sec)
    
    MysqL> exit
    Bye
    [root@linuxprobe ~]# scp MysqL_dump.sql vdevops.org@/tmp/
    cp: cannot create regular file ‘vdevops.org@/tmp/’: No such file or directory
    [root@linuxprobe ~]# scp MysqL_dump.sql vdevops.org:/tmp/
    The authenticity of host 'vdevops.org (10.1.1.56)' can't be established.
    ECDSA key fingerprint is f8:d2:55:54:8f:e8:43:e0:ee:aa:d6:8d:53:8c:8e:85.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added 'vdevops.org' (ECDSA) to the list of kNown hosts.
    MysqL_dump.sql
    @H_184_301@
  • Slave 端:
  • [root@vdevops ~]# MysqL -u root -p < /tmp/MysqL_dump.sql
    Enter password: 
    [root@vdevops ~]# MysqL -u root -p 
    Enter password: 
    Welcome to the MysqL monitor.  Commands end with ; or \g.
    Your MysqL connection id is 3
    Server version: 5.6.26-log MysqL Community Server (GPL)
    
    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> change master to
        -> master_host='10.1.1.53',# master ip
        -> master_user='replica',# replication ID
        -> master_password='password',# replication passwd
        -> master_log_file='MysqL-bin.000001',# bin-log number
        -> master_log_pos=400;          # position
    Query OK,0 rows affected,2 warnings (0.03 sec)
    
    MysqL> start slave;
    Query OK,0 rows affected (0.01 sec)
    
    MysqL> show slave status\G
    *************************** 1. row ***************************
                   Slave_IO_State: Waiting for master to send event
                      Master_Host: 10.1.1.53
                      Master_User: replica
                      Master_Port: 3306
                    Connect_Retry: 60
                  Master_Log_File: MysqL-bin.000001
              Read_Master_Log_Pos: 475
                   Relay_Log_File: MysqLd-relay-bin.000002
                    Relay_Log_Pos: 358
            Relay_Master_Log_File: MysqL-bin.000001
                 Slave_IO_Running: Yes
                Slave_sql_Running: Yes
                  Replicate_Do_DB: 
              Replicate_Ignore_DB: 
               Replicate_Do_Table: 
           Replicate_Ignore_Table: 
          Replicate_Wild_Do_Table: 
      Replicate_Wild_Ignore_Table: 
                       Last_Errno: 0
                       Last_Error: 
                     Skip_Counter: 0
              Exec_Master_Log_Pos: 475
                  Relay_Log_Space: 532
                  Until_Condition: None
                   Until_Log_File: 
                    Until_Log_Pos: 0
               Master_SSL_Allowed: No
               Master_SSL_CA_File: 
               Master_SSL_CA_Path: 
                  Master_SSL_Cert: 
                Master_SSL_Cipher: 
                   Master_SSL_Key: 
            Seconds_Behind_Master: 0
    Master_SSL_Verify_Server_Cert: No
                    Last_IO_Errno: 0
                    Last_IO_Error: 
                   Last_sql_Errno: 0
                   Last_sql_Error: 
      Replicate_Ignore_Server_Ids: 
                 Master_Server_Id: 101
                      Master_UUID: d47dddc3-9c70-11e6-8efb-000c29ffc05a
                 Master_Info_File: /var/opt/rh/rh-MysqL56/lib/MysqL/master.info
                        sql_Delay: 0
              sql_Remaining_Delay: NULL
          Slave_sql_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
               Master_Retry_Count: 86400
                      Master_Bind: 
          Last_IO_Error_Timestamp: 
         Last_sql_Error_Timestamp: 
                   Master_SSL_Crl: 
               Master_SSL_Crlpath: 
               Retrieved_Gtid_Set: 
                Executed_Gtid_Set: 
                    Auto_Position: 0
    1 row in set (0.00 sec)

    centos yum安装mysql

    centos yum安装mysql

    下载mysql的repo源

    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

    安装mysql-community-release-el7-5.noarch.rpm包

    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

    安装mysql

    sudo yum install mysql-server

    CentOS yum安装mysql&&jdk&&tomcat

    CentOS yum安装mysql&&jdk&&tomcat

    0. 创建个人文件夹

    [java] view plain copy
    1. #使用yum安装tomcat和MysqL
    2. #创建文件夹
    3. cd/usr/local
    4. mkdir hehe

    1.安装rzsz
    [java] view plain copy
    1. #1.安装rzsz
    2. yumlistlrzsz*
    3. yuminstalllrzsz-y

    2.安装JDK,path之类的已经自动设置好了
    [java] view plain copy
    1. #2.安装JDK
    2. yumlistjava*
    3. yuminstalljava-1.7.0-openjdk*-y

    3. 安装MysqL
    [java] view plain copy
    1. #3.安装MysqL
    2. yumlistMysqL*
    3. yuminstallMysqL-server*-y
    4. #修改/etc/my.cnf设置数据库默认编码以及存储位置,如果可能,优化内存配置
    5. vi/etc/my.cnf

    3.1 大致的MysqL配置文件如下:
    [java] view plain copy
    1. [MysqLd]
    2. #datadir=/var/lib/MysqL
    3. datadir=/usr/local/hehe/MysqL_data
    4. socket=/var/lib/MysqL/MysqL.sock
    5. user=MysqL
    6. #disablingsymbolic-linksisrecommendedtopreventassortedsecurityrisks
    7. symbolic-links=0
    8. default-character-set=utf8
    9. [MysqLd_safe]
    10. log-error=/var/log/MysqLd.log
    11. pid-file=/var/run/MysqLd/MysqLd.pid
    12. [MysqL]
    13. default-character-set=utf8

    其中,vi 默认进入时是命令模式,要进入编辑模式,可以使用按键 “i” 表示insert,插入模式。

    而退出编辑模式,使用Esc键,退出编辑模式后,就处于命令模式,在命令模式下输入的指令不会被加入到内容之中,

    在命令模式下,直接输入行号,比如 22,回车,则光标就跳到22行了,而使用冒号加命令,可以执行相关操作,比如


    [java] view plain copy
    1. :wq表示写入文件,并退出
    2. :wq!表示强制写入文件,并退出,适合只读文件什么的。
    3. :q表示退出不保存


    记得加回车键。

    关于MySQL的内存设置,也可以参考:MySQL 5.6初始配置调优

    当然,如果不考虑迁移性,建议使用 阿里云的 MysqL,5块钱一个月,很省心,如果你使用其他云平台,也可以使用云服务,高性能低价格,省时省心省力.


    4. 安装 tomcat

    [java] view plain copy
    1. #4.安装tomcat
    2. cd/usr/local
    3. wgethttp://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.63/bin/apache-tomcat-7.0.63.tar.gz
    4. tar-zxfapache-tomcat-7.0.63.tar.gz
    5. mvapache-tomcat-7.0.63tomcat

    4.1修改配置文件
    [java] view plain copy
    1. cd/usr/local/tomcat/conf
    2. #修改配置文件server.xml,不能有中文.
    3. #配置端口号,绑定域名,别名,以及设置线程池,映射context文件夹
    4. viserver.xml

    然后修改其中的Server部分,当然,可以采用ftp,或者其他工具下载到windows编辑好,再上传回去啦,记得如果有中文注释什么的,需要修改编码为UTF-8,否则纯英文,使用默认的ANSI也可以。
    [html] view plain copy
    1. <Servicename="Catalina">
    2. lt;Executorname="tomcatThreadPool"namePrefix="catalina-exec-"
    3. maxThreads="250"minSpareThreads="20"/>
    4. <Connectorport="80"protocol="HTTP/1.1"
    5. connectionTimeout="20000"
    6. redirectPort="8443"
    7. compression="on"
    8. compressionMinSize="2048"
    9. noCompressionUserAgents="gozilla,traviata"
    10. compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain,application/json,application/javascript,application/x-javascript"
    11. />
    12. <Connectorport="8009"protocol="AJP/1.3"redirectPort="8443"executor="tomcatThreadPool"/>
    13. <Enginename="Catalina"defaultHost="wwwhehe.com">
    14. <RealmclassName="org.apache.catalina.realm.UserDatabaseRealm"
    15. resourceName="UserDatabase"/>
    16. <Hostname="www.hehe.com"appBase="webapps"
    17. unpackWARs="true"autoDeploy="true"
    18. xmlValidation="false"xmlNamespaceAware="false">
    19. <Alias>localhost</Alias>
    20. <Alias>hehe.com</Alias>
    21. <Alias>hehe.cn</Alias>
    22. <Alias>www.hehe.cn</Alias>
    23. <ContextdocBase="/hehe/upload"path="/upload"/>
    24. <ContextdocBase="/hehe/myapp"path=""/>
    25. </Host>
    26. </Engine>
    27. </Service>

    5. 启动MysqLd 服务,以及tomcat
    [java] view plain copy
    1. --5.启动MysqLd服务,以及tomcat
    2. cd/usr/local/hehe
    3. mkdirMysqL_data
    4. #必须修改所属用户哦,如果修改了MysqL的数据文件保存目录的话
    5. chownMysqL:MysqLMysqL_data
    6. serviceMysqLdstart
    7. /usr/local/tomcat/bin/startup.sh


    5.1 设置Tomcat自动启动

    有很多种方式,比如设置服务,或者使用 rc.local 进行加载。

    修改/etc/rc.d/rc.local 文件:

    [plain] view plain copy
    1. vim/etc/rc.d/rc.local
    在里面增加启动Tomcat的脚本,然后保存. 最终结果如下所示:
    [plain] view plain copy
    1. [root@xxxbin]#cat/etc/rc.d/rc.local
    2. #!/bin/sh
    3. #
    4. #Thisscriptwillbeexecuted*after*alltheotherinitscripts.
    5. #Youcanputyourowninitializationstuffinhereifyoudon't
    6. #wanttodothefullSysVstyleinitstuff.
    7. touch/var/lock/subsys/local
    8. #starttomcat
    9. /usr/local/tomcat/bin/startup.sh
    可以看到,我们只增加了最后一行。意思是在Linux启动完成后,加载其他初始脚本完毕之后,执行启动Tomcat的命令.
    当然,启动其他程序也可以使用这种方式,但是就是土了一点,而且不可以使用 chkconfig 进行配置和调用(也就是说没有采用安装服务的方式.)

    6. 因为修改了相对应的tomcat的context,所以访问没有什么内容啦,需要在

    [html] view plain copy
    1. /hehe/myapp
    下面有对应的javaEE app才可以。

    centos6.0静态ip VMWare centos6.0静态ip设置

    centos6.0静态ip VMWare centos6.0静态ip设置

    centos6.0静态ip VMWare centos6.0静态ip设置

    因为使用虚拟机有时候ip会变化,用putty和一些工具不方便,所以就设置成静态ip

    方法/步骤

    1. 先获取window的ip地址

      ipconfig/all

    2. 按照window的ip地址设置虚拟机的ip地址

      记得虚拟机和window的链接方式使用桥接

      vi /etc/sysconfig/network-scripts/ifcfg-eth0

    #ip地址、子网掩码、网关都是按照window本机IPconfig设置的

    DEVICE="eth0" #设备别名

    HWADDR="00:0C:29:CD:71:3E"

    NM_CONTROLLED="yes"

    ONBOOT="yes"

    BOOTPROTO=static #设置网卡获得ip地址的方式为静态

    IPADDR=192.168.10.252 #ip地址 (处于一个网段下,但是不可以一样)

    NATMASK=255.255.255.0#子网掩码

    GATEWAY=192.168.10.1#网关ip

  • DNS配置

    vi /etc/resolv.conf

    nameserver 192.168.10.1

  • 5
  • 重启网络服务

    service network restart

    关于linux CentOS6.5 yum安装mysql 5.6的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于CentOS 7.2 Yum安装MySQL 5.6、centos yum安装mysql、CentOS yum安装mysql&&jdk&&tomcat、centos6.0静态ip VMWare centos6.0静态ip设置的相关知识,请在本站寻找。

    本文标签:

    上一篇linux 安装&配置JDK(linux安装配置jdk)

    下一篇使用 Windows Linux Subsystem 配置开发环境(linux开发windows应用)