• Linux上安装MySQL


    1.1. 准备工作

      Linux 使用的版本是centos 7,为方便起见,先把防火墙关闭,配置好网络,在安装部分,会分成两部分讲,首先讲单实例安装,也就是一台服务器上就装一个mysql,接下来就多实例安装,在一个服务器上安装2个甚至多个mysql.

    1.2. 单实例安装

    cp /soft/mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz  /usr/local/

    解压mysql/usr/local目录

    解压:

    tar -zxvf mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz

    安装需要的依赖

    yum install -y libaio

    具体安装

    shell> groupadd mysql

    shell> useradd -r -g mysql mysql

    shell> cd /usr/local

    shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz

    shell> ln -s full-path-to-mysql-VERSION-OS mysql

    shell> cd mysql

    shell> mkdir mysql-files

    shell> chmod 770 mysql-files

    shell> chown -R mysql .

    shell> chgrp -R mysql .

    shell> bin/mysqld --initialize --user=mysql     # MySQL 5.7.6 and up

    shell> bin/mysql_ssl_rsa_setup              # MySQL 5.7.6 and up

    shell> chown -R root .

    shell> chown -R mysql data mysql-files

    shell> bin/mysqld_safe --user=mysql &

    # Next command is optional

    shell> cp support-files/mysql.server /etc/init.d/mysql.server

    配置环境变量:

    export PATH=/usr/local/mysql/bin:$PATH

    配置开启启动

    chkconfig mysql.server on

    chkconfig --list

    登陆,修改密码

    set password = 'root1234%';

    允许远程登陆

     GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root1234%'

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

    flush privileges;  

    启动的时候可能会报错

     

    这是因为mysql启动的时候需要配置文件,而在安装centos的时候,哪怕是mini版本都会有个默认的配置在/etc目录中

    /usr/local/mysql/bin/mysqld --verbose --help |grep -A 1 'Default options'

    Default options are read from the following files in the given order:

    /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

    Mysql启动的时候会以上面所述的顺序加载配置文件

    如果报错,先重命名my.cnf文件

    1.3. 多实例安装

    以前一些很low的方法是,解压两个mysql,分别放到不同文件夹,其实在mysql中已经考虑到了多实例安装的情况。也有相应的脚本命令的支持。

    现在要求装两个mysql 一个33073308

    新建 /etc/my.cnf 配置如下

    [mysqld]

    sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER"

    [mysqld_multi]

    mysqld = /usr/local/mysql/bin/mysqld_safe

    mysqladmin = /usr/local/mysql/bin/mysqladmin

    log = /var/log/mysqld_multi.log

    [mysqld1]

    server-id = 11

    socket = /tmp/mysql.sock1

    port = 3307

    datadir = /data1

    user = mysql

    performance_schema = off

    innodb_buffer_pool_size = 32M

    skip_name_resolve = 1

    log_error = error.log

    pid-file = /data1/mysql.pid1

    [mysqld2]

    server-id = 12

    socket = /tmp/mysql.sock2

    port = 3308

    datadir = /data2

    user = mysql

    performance_schema = off

    innodb_buffer_pool_size = 32M

    skip_name_resolve = 1

    log_error = error.log

    pid-file = /data2/mysql.pid2

    创建2个数据目录

    mkdir /data1

    mkdir /data2

    chown mysql.mysql /data{1..2}

    mysqld --initialize --user=mysql --datadir=/data1

    mysqld --initialize --user=mysql --datadir=/data2

    cp /usr/local/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld_multid

    配置开机启动

    chkconfig mysqld_multid on

    查看状态

    mysqld_multi report

     

    这个时候发现还需要perl的环境,安装

    yum -y install perl perl-devel

    在运行,发现已经有实例了

    mysqld_multi report

     

    mysqld_multi start

    启动,分别修改密码,允许远程连接

     mysql -u root -S /tmp/mysql.sock1 -p -P3307

     mysql -u root -S /tmp/mysql.sock2 -p -P3308

    set password = 'root1234%';

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root1234%';

    flush privileges;  

  • 相关阅读:
    GridView编辑删除操作
    hdu 4857 逃生 拓扑排序+PQ,剥层分析
    每日回顾Shell —cat,tail,head
    uva:10700
    Unity多玩家网络游戏开发教程1章Unity带有网络功能
    android com.handmark.pulltorefresh 使用技巧
    Jsoup 抓取和数据页 认识HTTP头
    JDK8在Java转让Javascript脚本引擎动态地定义和运行代码
    2013-2014约半学期的学习和规划研究综述
    Javascript 设计模式 辛格尔顿
  • 原文地址:https://www.cnblogs.com/Soy-technology/p/11037458.html
Copyright © 2020-2023  润新知