Mysql 安装

 

1. 源码安装

    wget https://downloads.mysql.com/archives/get/file/mysql-5.6.36.tar.gz
    yum install -y gcc gcc-c++ automake autoconf
    yum -y install cmake bison-devel ncurses-devel libaio-devel

    预编译:

    cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.36 \
    -DMYSQL_DATADIR=/usr/local/mysql-5.6.36/data \
    -DMYSQL_UNIX_ADDR=/usr/local/mysql-5.6.36/tmp/mysql.sock \
    -DDEFAULT_CHARSET=utf8 \
    -DDEFAULT_COLLATION=utf8_general_ci \
    -DWITH_EXTRA_CHARSETS=all \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DWITH_FEDERATED_STORAGE_ENGINE=1 \
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
    -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
    -DWITH_ZLIB=bundled \
    -DWITH_SSL=bundled \
    -DENABLED_LOCAL_INFILE=1 \
    -DWITH_EMBEDDED_SERVER=1 \
    -DENABLE_DOWNLOADS=1 \
    -DWITH_DEBUG=0

    编译 && 安装:

    make && make install


    安装后操作:

    useradd -s /sbin/nologin mysql -M
    ln -s /usr/local/mysql-5.6.36  /usr/local/mysql
    chown -R mysql.mysql /usr/local/mysql/data
    /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    /bin/cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
    /bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile
    . /etc/profile
    chkconfig --add mysqld
    /usr/local/mysql/bin/mysqladmin -u root password 'xx'



    启动错误:

    Starting MySQL.Logging to '/usr/local/mysql-5.6.36/data/db01.err'.
    171113 13:07:01 mysqld_safe Directory '/usr/local/mysql-5.6.36/tmp' for UNIX socket file don't exists.
     ERROR! The server quit without updating PID file (/usr/local/mysql-5.6.36/data/db01.pid).

    mkdir /usr/local/mysql-5.6.36/tmp
    chown -R mysql.mysql /usr/local/mysql-5.6.36/tmp


-----------------------------------------------------------------------------

    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/local/mysql/bin/mysqladmin -u root password 'new-password'
      /usr/local/mysql/bin/mysqladmin -u root -h iZ2zedsleruuvamkhs3he4Z password 'new-password'

    Alternatively you can run:

      /usr/local/mysql/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/local/mysql/bin/mysqld_safe &

    You can test the MySQL daemon with mysql-test-run.pl

      cd mysql-test ; perl mysql-test-run.pl

    Please report any problems at http://bugs.mysql.com/

    The latest information about MySQL is available on the web at

      http://www.mysql.com

    Support MySQL by buying support/licenses at http://shop.mysql.com

    New default config file was created as /usr/local/mysql/my.cnf and
    will be used by default by the server when you start it.
    You may edit this file to change server settings

--------------------------------------------------------------------------------
View Code

2. centos7安装 

    rm -rf /var/lib/mysql/*

    yum -y install mariadb mariadb-server

    systemctl start mariadb

    systemctl enable mariadb

    #配置
    mysql_secure_installation

    #先删除多余的用户
    select Host,User,Password from user;
mariadb

3. 授权 

    #创建用户
    create user 'xiao'@'127.0.0.1' identified by 'xxx';

    #创建数据库
    create database cnblogs CHARACTER SET utf8  COLLATE utf8_general_ci;

    #授权
    grant all on cnblogs.* to "xiao"@"127.0.0.1" identified by 'xxx'; 
授权

4. 备份 

http://edu.51cto.com/course/course_id-808.html
1、压缩备份
    mysqldump -uroot -p123456 -B oldboy |gzip >/opt/mysql_bak.sql.gz
    
2、备份多个库
    mysqldump -uroot -p123456 -A |gzip >/opt/mysql_bak.sql.gz
    mysqldump -uroot -p123456 -B oldboy oldgirl|gzip >/opt/mysql_bak.sql.gz
    mysql -uroot -p123456 -e "show databases;" |egrep -vi "data|infor|per"|sed -r 's#^([a-z].*$)#mysqldump -uroot -p123456 --events -B \1|gzip >/opt/\1.sql.gz#g'|bash
    
3、备份test库下的test表
    mysqldump -uroot -p123456 test test >/opt/test.sql
    
4、备份表结构
    mysqldump -uroot -p123456 -d test test >/opt/test.sql

5、备份表的数据
    mysqldump -uroot -p123456 -t test test >/opt/test.sql
    
--------------增量备份案例-------------
1、先完整备份
    mysqldump -uroot -p123456 -F -B --master-data=2 oldboy|gzip >/opt/bak_$(date +%F).sql.gz

2、数据库中继续增加数据,然后删除数据库
    mysql>insert into test(name) values("oldboy5676666666");
    mysql>insert into test(name) values("oldboy5676666666");
    mysql>insert into test(name) values("oldboy5676666666");
    mysql>drop database oldboy;
3、
    gzip -d bak_2016-08-11.sql.gz
    grep -i "change" bak_2016-08-11.sql 
        -- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000017', MASTER_LOG_POS=107;
4、恢复数据
    cp mysql-bin.000017 /opt/
    mysqlbinlog -d oldboy mysql-bin.000017 >bin.sql     只找和oldboy有关的库
    vim bin.sql 
        删除drop database oldboy
    mysql -uroot -p123456 <bak_2016-08-11.sql
    mysql -uroot -p123456 oldboy <bin.sql
备份

 

 

 

链接

posted @ 2018-03-16 20:13  golangav  阅读(396)  评论(0编辑  收藏  举报