MySQL binary installation

Source: Internet
Author: User

Centos7: Binary method to install MySQL database:
# # #安装前提: Make sure the MARIADB service is not installed and should not contain 3306 ports;
# 1 Download the installation package

在httpd://downloads.mariadb.org网页下载二进制安装包"mariadb-10.2.12-linux-x86_64.tar.gz"

# > 2 database runs with MySQL user, so create an account

    useradd -r mysql -s /sbin/nologin

3 extract "mariadb-10.2.12-linux-x86_64.tar.gz" file, because the binary package is compiled, the path specified is/usr/local;

    tar zxvf mariadb-10.2.12-linux-x86_64.tar.gz -C /usr/local

4 The name of the extract is completed when it was compiled named MySQL so to create a soft connection, point to MySQL

    ln -s mariadb-10.2.12-linux-x86_64/ mysql

5 After the decompression is complete, the files in the file does not specify all groups of owners, it is recommended to change the owner domain all groups to MySQL

    chown -R mysql.mysql mysql

6 put the path of the binary program into path for easy global use

    echo ‘PATH=/usr/local/mysql/bin:$PATH‘  > /etc/profile.d/mysql.sh    source /etc/profile.d/mysql.sh

7 the folder where the database is to be stored, that is, the location of a large number of data files, it is recommended to store the operating system space and storage space separation, and the proposed use of logical volumes

    1 虚拟机中添加了一块儿大小为20G的磁盘    2 分区磁盘并且修改为LVM      fdisk /dev/sdb        n:开始分区        p:默认主分区        大小统统默认直接回车就可以,根据实际情况定义        t:修改分区类型        8e:修改为LVM版        w :保存退出    3 pvcreate /dev/sdb1                        #创建pv      vgcreate vg0-mysql /dev/sdb1 -s 16M       #创建vg并命名为vg0-mysql而且pe大小为16M      lvcreate -n lv_mysqldata -l 100%FREE vg0-mysql #创建lv并命名为lv_mysqldata并且使用vg0-mysql上的所有剩余空间    4 mkfs.xfs /dev/vg0-mysql/lv_mysqldata      #给新创建的lv创建xfs的文件系统    5 mkdir /data/mysqldb                                 #创建给逻辑卷挂载的目录    6 blkid                                                          #查找出逻辑卷的uuid    7 vim /etc/fstab                                           #在文件中添加如下内容,注意UUID是不同的,实验环境是这个      UUID=784ecb9c-de51-4140-9676-a0161ba205c1 /data/mysqldb           xfs     defaults        0 0        8 mount -a                                  #执行文件中没有挂载的那一行,永久挂载

8 to change the owner of the created directory and the owning group to MySQL, because it is for MySQL to do the directory for storing data, so must have permissions

    chown -R mysql.mysql /data/mysqldb

9 based on security considerations, we can change the directory permissions of the database to 770, that is, other than MySQL users will not be able to get in

    chmod 770 /data/mysqldb

10 to execute scripts/mysql_install_db this script under/usr/local/mysql/to install the database, and to execute DataDir is the database storage directory and run user--user;

出现OK字样则证明运行成功,信息中有一条执行./bin/mysql_secure_installation的指令,这是安全脚本,默认安装完数据库是不存在口令的,所以可以运行一下此脚本;     1 cd /usr/local/mysql    2 scripts/mysql_install_db --datadir=/data/mysqldb --user=mysql

11 If there is no security restrictions, you can start the service, but note that the default configuration file is/etc/my.cnf, in which the database path domain socket path is specified by default, but the configuration is also slightly less, so you can/usr/local/mysql/ Modify the configuration file for a specific environment under support-files

    my-small.cnf:小环境使用    my-medium.cnf:稍小环境使用    my-large.cnf:大的环境使用    my-huge.cnf:巨大的环境使用(其实巨大也没多大1G-2G都算巨大了= =)每一个下面都有信息,实验当中使用此配置文件;    my-innodb-heavy-4G.cnf:4G内存的环境下使用

12 Copy This configuration file to/etc/and name it my.cnf

    cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf    **13 复制过去之后进行编辑修改,当中存在[mysqld]与[client]两个语句块儿,在[mysqld]下添加一行用于修改数据库路径:datadir = /data/mysqldb**    **14 在/usr/local/mysql/support-files下还存在一个用于服务启动停止的脚本,名为mysql.server,将此文件复制到/etc/init.d/下命名为mysqld方便全局使用**        cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld        并且添加到chkconfig中开机自启动:chkconfig --add mysqld

15 Starting the Service

    service mysqld start注意:当服务启动后,在/tmp/下会生成一个粉色的mysql.sock文件,当服务停止的时候,文件也会消失,因为在配置文件当中的定义就是/tmp/mysql.sock

16 at this time the service has been started, but the default is no password, so that anyone can log in to the database and a series of operations, in the database will appear by default several tables, these tables are stored in the location under/data/mysqldb;

    mysql              #此命令可直接登录进数据库    show databases;    #这是sql语句,在数据库中执行可查看当时数据库中拥有的表;    drop database test; #删除名为test的数据库,删除后在/data/mysqldb下就会消失;

17 Enter the database to see what insecure users exist;

        mysql                                           #连接进数据库        select user,host from mysql.user;               #查看mysql库中的user表下的user和host字段信息;

18 running Mysql_secure_installation script in Linux environment to strengthen security;

    mysql_secure_installation         #按照脚本的提示一步一步往下走即可

19 When the modification is complete and then use the empty password there is no way to connect, so use the following method to connect

    mysql -uroot -pmysql                       #-u:指定登录用户                                                               #-p:指定登录密码,mysql是我刚刚执行那个脚本的时候设置的密码

CENTOS6 above requires a binary installation, the same as the above operation, is the package is not the same, the package named "Mariadb-5.5.59-linux-x86_64.tar"

MySQL binary installation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.