zoukankan      html  css  js  c++  java
  • MariaDB10源码安装

    源码安装MariaDB10

    官方网站MariaDB <wbr><wbr>yum安装

    https://mariadb.com/

    https://downloads.mariadb.org

    http://mirrors.ctyun.cn/MariaDB/

    环境:CentOS6.5 x64

    一.准备编译环境
    1.卸载linux预装的mysql-libs

    rpm -e --nodeps mysql-libs

    2.安装编译必备工具及库

    yum -y install gcc gcc-c++  cmake ncurses-devel bison libxml2-devel openssl-devel libevent-devel #必选

    libaio-devel pam-devel  boost-devel valgrind-devel   #可选

    libnl-devel popt-devel popt-static   #其它

    #libevent-devel提供"event.h"


    二、安装MariaDB

    1.下载相关软件源码包

    wget --no-check-certificate http://mirrors.neusoft.edu.cn/mariadb/mariadb-10.0.14/source/mariadb-10.0.14.tar.gz

    2.建mysql服务的用户和用户组

    [root@node2 rhel6]# groupadd mysql
    [root@node2 rhel6]# useradd -s /sbin/nologin -g mysql -M mysql
    [root@node2 rhel6]# id mysql
    uid=500(mysql) gid=500(mysql) groups=500(mysql)

    3.解压mariadb到临时安装目录,通常放在/usr/local/src目录下

    [root@node2 ~]# ls
    mariadb-10.0.14.tar.gz
    [root@node2 ~]# tar -xvf mariadb-10.0.14.tar.gz -C /usr/local/src/


    4.通过cmake编译安装

    [root@node2 ~]# cd /usr/local/src/mariadb-10.0.14/
    [root@node2 mariadb-10.0.14]# mkdir rhel6
    [root@node2 mariadb-10.0.14]# cd rhel6/
    [root@node2 rhel6]# cmake

    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
    -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock
    -DMYSQL_DATADIR=/var/lib/mysql
    -DSYSCONFDIR=/etc
    -DMYSQL_USER=mysql
    -DMYSQL_TCP_PORT=3306
    -DWITH_XTRADB_STORAGE_ENGINE=1
    -DWITH_INNOBASE_STORAGE_ENGINE=1
    -DWITH_PARTITION_STORAGE_ENGINE=1
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1
    -DWITH_MYISAM_STORAGE_ENGINE=1
    -DWITH_READLINE=1
    -DENABLED_LOCAL_INFILE=1
    -DWITH_EXTRA_CHARSETS=1
    -DWITH_BIG_TABLES=1
    -DWITH_EMBEDDED_SERVER=1
    -DWITH_DEBUG=0
    -DDEFAULT_CHARSET=utf8
    -DDEFAULT_COLLATION=utf8_general_ci
    -DEXTRA_CHARSETS=all
    -DWITH_SSL=system  ..


    [root@node2 rhel6]# make && make install


    三.配置MariaDB

    1.将mysql管理调式工具添加到PATH路径

    [root@node2 ~]# echo 'PATH=$PATH:/usr/local/mysql/bin' >>/etc/profile

    [root@node2 ~]# source /etc/profile

    顺道也加一个man记录
    [root@node2 ~]# ls /usr/local/mysql/man/
    man1  man8
    [root@node2 ~]# echo MANPATH /usr/local/mysql/man >>/etc/man.config

    2.初始化mariadb
    [root@node2 ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/var/lib/mysql
    WARNING: The host 'node2' could not be looked up with resolveip.
    This probably means that your libc libraries are not 100 % compatible
    with this binary MariaDB version. The MariaDB daemon, mysqld, should work
    normally with the exception that host name resolving will not work.
    This means that you should use IP addresses instead of hostnames
    when specifying MariaDB privileges !
    Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...
    141124 14:40:26 [Note] InnoDB: Using mutexes to ref count buffer pool pages
    141124 14:40:26 [Note] InnoDB: The InnoDB memory heap is disabled
    141124 14:40:26 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
    ... ...

    Please report any problems at http://mariadb.org/jira

    The latest information about MariaDB is available at http://mariadb.org/.
    You can find additional information about the MySQL part at:
    http://dev.mysql.com
    Support MariaDB development by buying support/new features from
    SkySQL Ab. You can contact us about this at sales@skysql.com.
    Alternatively consider joining our community based development effort:
    http://mariadb.com/kb/en/contributing-to-the-mariadb-project/

    3.配置/etc/my.cnf和/etc/init.d/mysql

    [root@node2 ~]# cp /usr/local/src/mariadb-10.0.14/rhel6/support-files/my-huge.cnf /etc/my.cnf

    [root@node2 ~]# cat /etc/my.cnf
    # Example MariaDB config file for very large systems.
    #
    # This is for a large system with memory of 1G-2G where the system runs mainly
    # MariaDB.
    #
    # MariaDB programs look for option files in a set of
    # locations which depend on the deployment platform.
    # You can copy this option file to one of those
    # locations. For information about these locations, do:
    # 'my_print_defaults --help' and see what is printed under
    # Default options are read from the following files in the given order:
    # More information at: http://dev.mysql.com/doc/mysql/en/option-files.html
    #
    # In this file, you can use all long options that a program supports.
    # If you want to know which options a program supports, run the program
    # with the "--help" option.

    # The following options will be passed to all MySQL clients
    [client]
    #password    = your_password
    port        = 3306
    socket        = /var/lib/mysql/mysql.sock

    # Here follows entries for some specific programs

    # The MySQL server
    [mysqld]
    port        = 3306
    socket        = /var/lib/mysql/mysql.sock

    log-error     = /var/lib/mysql/mysqld.log
    pid-file        = /var/lib/mysql/mysqld.pid

    skip-external-locking
    key_buffer_size = 384M
    max_allowed_packet = 1M
    table_open_cache = 512
    sort_buffer_size = 2M
    read_buffer_size = 2M
    read_rnd_buffer_size = 8M
    myisam_sort_buffer_size = 64M
    thread_cache_size = 8
    query_cache_size = 32M
    # Try number of CPU's*2 for thread_concurrency
    thread_concurrency = 8

    # Point the following paths to a dedicated disk
    #tmpdir        = /tmp/

    # Don't listen on a TCP/IP port at all. This can be a security enhancement,
    # if all processes that need to connect to mysqld run on the same host.
    # All interaction with mysqld must be made via Unix sockets or named pipes.
    # Note that using this option without enabling named pipes on Windows
    # (via the "enable-named-pipe" option) will render mysqld useless!
    #
    #skip-networking

    # Replication Master Server (default)
    # binary logging is required for replication
    log-bin=mysql-bin

    # required unique id between 1 and 2^32 - 1
    # defaults to 1 if master-host is not set
    # but will not function as a master if omitted
    server-id    = 1

    # Replication Slave (comment out master section to use this)
    #
    # To configure this host as a replication slave, you can choose between
    # two methods :
    #
    # 1) Use the CHANGE MASTER TO command (fully described in our manual) -
       the syntax is:
    #
       CHANGE MASTER TO MASTER_HOST=, MASTER_PORT=,
       MASTER_USER=, MASTER_PASSWORD= ;
    #
       where you replace , , by quoted strings and
       by the master's port number (3306 by default).
    #
       Example:
    #
       CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
       MASTER_USER='joe', MASTER_PASSWORD='secret';
    #
    # OR
    #
    # 2) Set the variables below. However, in case you choose this method, then
       start replication for the first time (even unsuccessfully, for example
       if you mistyped the password in master-password and the slave fails to
       connect), the slave will create a master.info file, and any later
       change in this file to the variables' values below will be ignored and
       overridden by the content of the master.info file, unless you shutdown
       the slave server, delete master.info and restart the slaver server.
       For that reason, you may want to leave the lines below untouched
       (commented) and instead use CHANGE MASTER TO (see above)
    #
    # required unique id between 2 and 2^32 - 1
    # (and different from the master)
    # defaults to 2 if master-host is set
    # but will not function as a slave if omitted
    #server-id       = 2
    #
    # The replication master for this slave - required
    #master-host     
    #
    # The username the slave will use for authentication when connecting
    # to the master - required
    #master-user     
    #
    # The password the slave will authenticate with when connecting to
    # the master - required
    #master-password =  
    #
    # The port the master is listening on.
    # optional - defaults to 3306
    #master-port    
    #
    # binary logging - not required for slaves, but recommended
    #log-bin=mysql-bin
    #
    # binary logging format - mixed recommended
    #binlog_format=mixed

    # Uncomment the following if you are using InnoDB tables
    #innodb_data_home_dir = /var/lib/mysql
    #innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend
    #innodb_log_group_home_dir = /var/lib/mysql
    # You can set .._buffer_pool_size up to 50 - 80 %
    # of RAM but beware of setting memory usage too high
    #innodb_buffer_pool_size = 384M
    #innodb_additional_mem_pool_size = 20M
    # Set .._log_file_size to 25 % of buffer pool size
    #innodb_log_file_size = 100M
    #innodb_log_buffer_size = 8M
    #innodb_flush_log_at_trx_commit = 1
    #innodb_lock_wait_timeout = 50

    [mysqldump]
    quick
    max_allowed_packet = 16M

    [mysql]
    no-auto-rehash
    # Remove the next comment character if you are not familiar with SQL
    #safe-updates

    [myisamchk]
    key_buffer_size = 256M
    sort_buffer_size = 256M
    read_buffer = 2M
    write_buffer = 2M

    [mysqlhotcopy]
    interactive-timeout
    ##Log
    log_error = /var/log/mysql/mysqld-error.log
    long_query_time = 1
    slow_query_log
    slow_query_log_file = /var/log/mysql/mysqld-slow.log

    ##Other
    #max_connections = 1000
    #open_files_limit = 65535


    [root@node2 ~]# cp /usr/local/src/mariadb-10.0.14/rhel6/support-files/mysql.server /etc/init.d/mysql
    [root@node2 ~]# chmod +x /etc/init.d/mysql
    [root@node2 ~]# ll /etc/init.d/mysql
    -rwxr-xr-x. 1 root root 12055 Nov 24 14:25 /etc/init.d/mysql


    4.启服务

    [root@node2 ~]# /etc/init.d/mysql start
    Starting MySQL. SUCCESS!
    [root@node2 ~]# /etc/init.d/mysql status
     SUCCESS! MySQL running (13372)
    [root@node2 ~]# netstat -tunlp|grep mysqld
    tcp            0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      13372/mysqld       
    [root@node2 ~]# chkconfig mysql on
    [root@node2 ~]# chkconfig --list mysql
    mysql              0:off    1:off    2:on    3:on    4:on    5:on    6:off


    5.安全设置

    [root@rhel7-test1 ~]# mysql_secure_installation
    /usr/local/mysql/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
     

         SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

    In order to log into MariaDB to secure it, we'll need the current
    password for the root user.  If you've just installed MariaDB, 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 MariaDB
    root user without the proper authorisation.

    Set root password? [Y/n] y 
    New password:
    Re-enter new password:
    Password updated successfully!
    Reloading privilege tables..
     ... Success!
    这里设置mariadb的root密码

    By default, a MariaDB installation has an anonymous user, allowing anyone
    to log into MariaDB 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? [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? [Y/n] y
     ... Success!
    不允许mariadb root用户远程登录
    By default, MariaDB 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 and access to it? [Y/n] y
     - Dropping test database...
     ... Success!
     - Removing privileges on test database...
     ... Success!
    删除test数据库
    Reloading the privilege tables will ensure that all changes made so far
    will take effect immediately.

    Reload privilege tables now? [Y/n] y
     ... Success!
    权限下发
    Cleaning up...

    All done!  If you've completed all of the above steps, your MariaDB
    installation should now be secure.

    Thanks for using MariaDB!

    也可以手动完成,
    mysql -e "grant all privileges on *.* to 'root'@'127.0.0.1' identified by 'dbrootpwd' with grant option;"
    
    mysql -e "grant all privileges on *.* to 'root'@'localhost' identified by 'dbrootpwd' with grant option;"
    mysql -uroot -pdbrootpwd -e "delete from mysql.user where Password='';"
    mysql -uroot -pdbrootpwd -e "delete from mysql.db where User='';"
    mysql -uroot -pdbrootpwd -e "drop database test;"


    四.测试
    [root@node2 ~]# mysql -u root -p
    Enter password:
    Welcome to the MariaDB monitor.  Commands end with ; or g.
    Your MariaDB connection id is 12
    Server version: 10.0.14-MariaDB-log Source distribution

    Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.

    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

    MariaDB [(none)]> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    3 rows in set (0.01 sec)

    MariaDB [(none)]> show engines;
    +--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
    | Engine             | Support | Comment                                                                    | Transactions | XA   | Savepoints |
    +--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
    | MRG_MyISAM         | YES     | Collection of identical MyISAM tables                                      | NO           | NO   | NO         |
    | PERFORMANCE_SCHEMA | YES     | Performance Schema                                                         | NO           | NO   | NO         |
    | CSV                | YES     | CSV storage engine                                                         | NO           | NO   | NO         |
    | BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears)             | NO           | NO   | NO         |
    | MyISAM             | YES     | MyISAM storage engine                                                      | NO           | NO   | NO         |
    | MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables                  | NO           | NO   | NO         |
    | InnoDB             | DEFAULT | Percona-XtraDB, Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |
    | Aria               | YES     | Crash-safe tables with MyISAM heritage                                     | NO           | NO   | NO         |
    +--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
    8 rows in set (0.01 sec)

    MariaDB [(none)]> quit
    Bye


  • 相关阅读:
    JavaScript的函数(二)
    Python:os.walk()和os.path.walk()用法
    Python:代码单元、代码点介绍
    Python:如何去掉字符串中不需要的字符
    Python:更改字典的key
    Python:如何对字符串进行左、右、居中对齐
    Python:format()方法
    日常开发之缓存技术
    Web系统大规模并发——秒杀与抢购 秒杀系统优化与预防措施
    PHP之位运算符
  • 原文地址:https://www.cnblogs.com/lixuebin/p/10814475.html
Copyright © 2011-2022 走看看