table of Contents
CentOS6.9 install MySQL
Linux installation of MySQL 4 ways:
1. binary mode
Features: no need to install, decompression can be used, can not customize function
2. compile and install
Features: customizable, slow installation
5.5之前: ./configure make make install
After 5.6: cmake gmake
3. rpm,yum
Features: Easy installation, installation speed, can not be customized
4. compile and then an RPM, making the source yum, yum then install
Features: simple, fast, customizable, complex, long production time
Companies have chosen:
SMEs: The above methods can, operation and maintenance tend to compile and install, dba tend to choose binary
Large enterprises: the fourth choice
Binary installation steps:
Preparing the Environment
Linux system as a demonstration here to CentOS6.9
mysql installation package: mysql-5.7.19-linux-glibc2.5-x86_64.tar.gz
installation
Extracting mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz, and copied to the directory /application/mysql-5.7.24
mkdir -p /tools mkdir -p /application cd /tools tar -zxf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz mv mysql-5.7.24-linux-glibc2.12-x86_64 /application/mysql-5.7.24 ln -s /application/mysql-5.7.24 /application/mysql5.7
Add a mysql user
useradd -s /sbin/nologin -M mysql # 提前创建安装目录 mkdir -p /application/mysql-5.7.24
Mysql modify the working directory permissions
chown -R mysql.mysql /application/mysql-5.7.24 /application/mysql5.7
Install mysql
cd /application/mysql5.7 ./bin/mysqld --initialize --user=mysql --basedir=/application/mysql5.7 --datadir=/application/mysql5.7/data # 执行完上诉命令,输出的信息中存在mysql的登录密码。(最后一行的最后一串字符就是密码)
Copy the mysql command to the system startup file
cp /application/mysql5.7/support-files/mysql.server /etc/init.d/mysqld
Mysql will start the file path added to the system environment variables
echo "PATH=/application/mysql5.7/bin:$PATH" >> /etc/profile . /etc/profile # 让/etc/profile文件生效
Mysql configuration profiles
# 编辑配置文件 vim /etc/my.cnf ************************以下为配置,直接复制粘贴*************************** [mysql] socket=/application/mysql5.7/data/mysql.sock [mysqld] port=3306 socket=/application/mysql5.7/data/mysql.sock basedir=/application/mysql5.7 datadir=/application/mysql5.7/data
Start mysql service
/etc/init.d/mysqld start
Login mysql service
mysql -u root -p密码 # 密码是第4步中的内容
The last successful login interface
change Password
alter user user() identified by "新密码";
Here binary installation is over
Compile and install steps:
Preparing the Environment
Linux system as a demonstration here to CentOS6.9
mysql installation package: mysql-5.6.37.tar.gz (address detail later step)
installation
Installation dependencies
yum install -y ncurses-devel libaio-devel gcc gcc-c++
Install cmake, compiler
yum install cmake -y
Create a user, for use running mysql
useradd -s /sbin/nologin -M mysql # 提前创建安装目录 mkdir -p /application/mysql-5.6.36
Download the installation package
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.37.tar.gz
Unpack
tar -zxvf mysql-5.6.37.tar.gz # 进入对应的目录中 cd mysql-5.6-37
Compile
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.36 \ -DMYSQL_DATADIR=/application/mysql-5.6.36/data \ -DMYSQL_UNIX_ADDR=/application/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 *******************************参数含义***************************** cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.37 \ # 指定安装目录,类似window选择目录安装软件,默认最后一级目录系统自动创建。 -DMYSQL_DATADIR=/application/mysql-5.6.37/data \ # 指定数据目录,一般都是跟随安装下 -DMYSQL_UNIX_ADDR=/application/mysql-5.6.37/tmp/mysql.sock \ # 指定sock文件位置 -DDEFAULT_CHARSET=utf8 \ # 字符编码 -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS=all \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ # 启用该引擎的支持。语法为:-DWITH_<ENGINE>_STORAGE_ENGINE=1 禁用语法为:-DWITHOUT_<ENGINE>_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 # make 开始编译,make install 安装 **********************常见的编译参数************************* -DMYSQL_USER=mysql # 设置mysql服务的用户,必须真实存在 -DMYSQL_TCP_PORT=3306 # 设置mysql服务的端口,默认为3306
Please refer to the official document compiled more: https://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html#option_cmake_storage_engine_options
Create a soft link
ln -s /application/mysql-5.6.37 /application/mysql5.6
Permission to modify the installation directory
chmod +w /application/mysql-5.6.37 chmod +w /application/mysql5.6 chown -R mysql:mysql /application/mysql5.6 chown -R mysql:mysql /application/mysql-5.6.37
Copy the configuration file to the Linux system directory, and add the following to the file /etc/my.cnf
cd /application/mysql-5.6.37 cp -f support-files/my-default.cnf /etc/my.cnf # 在/etc/my.cnf中添加如下内容: -----------------------------/etc/my.cnf内容------------------------ [mysql] socket=/application/mysql5.6/data/mysql.sock [mysqld] port=3306 socket=/application/mysql5.6/data/mysql.sock basedir=/application/mysql5.6 datadir=/application/mysql5.6/data -------------------------------------------------------------------
Perform initial configuration script, create the system comes with a database and table, pay attention to the configuration file path
cd /application/mysql5.6/scripts/ ./mysql_install_db --defaults-file=/etc/my.cnf --basedir=/application/mysql5.6 --datadir=/application/mysql5.6/data --user=mysql # --defaults-file 指定mysql的配置文件 # --basedir 指定mysql工作目录 # --datadir 指定mysql数据目录 # -user 指定mysql软件运行的用户
Copy the mysql startup files to the system directory (similar to the windows of the software start the program, copied to the desktop, it is conducive to quick start)
cd /application/mysql5.6 cp support-files/mysql.server /etc/init.d/mysqld
Authorization mysqld file execute permissions
chmod +x /etc/init.d/mysqld
Set boot from the start (set according to their own hobby)
chkconfig mysqld on
Start msyql Service
/etc/init.d/mysqld start
Mysql service to add the path to the environment variable
echo "PATH=/application/mysql5.6/bin:$PATH" >> /etc/profile . /etc/profile # 让/etc/profile文件生效
Mysql password login
/application/mysql5.6/bin/mysqladmin -u root password '新密码' -S /application/mysql5.6/data/mysql.sock
Login mysql service
mysql -uroot -p新密码 # 注意-p后面直接接密码,不要空格
After a successful login interface shown