MySQL安装(yum、二进制、源码)

MySQL安装(yum、二进制、源码)

目录

  1.1 yum安装... 2
  1.2 二进制安装-mysql-5.7.17. 3
1.2.1 准备工作... 3
1.2.2 解压、移动、授权... 3
1.2.3 mysql配置... 3
1.2.4 启动事项... 4
  1.3 源码安装- mysql-5.6.36. 4
1.3.1 准备工作... 4
1.3.2 源码安装前... 4
1.3.3 源码安装... 5
1.3.4 源码安装后... 5
  1.4 优化设置... 6
1.4.1 开机自启... 6
1.4.2 加入环境变量... 6
1.4.3 设置密码... 6
1.4.4 清理用户及无用数据库(基本优化) 6

###=============================================###

1.1 yum安装

yum安装
#yum安装
yum install mysql mysql-server mysql-devel
#启动
/etc/init.d/mysqld start
#进入mysql
mysql

安装的具体包列表

==================================================
Package Arch Version Repository Size
==================================================
Installing:
mysql x86_64 5.1.73-8.el6_8 base 895 k
mysql-devel x86_64 5.1.73-8.el6_8 base 130 k
mysql-server x86_64 5.1.73-8.el6_8 base 8.6 M
Installing for dependencies:
keyutils-libs-devel x86_64 1.4-5.el6 base 29 k
krb5-devel x86_64 1.10.3-65.el6 base 504 k
libcom_err-devel x86_64 1.41.12-23.el6 base 33 k
libkadm5 x86_64 1.10.3-65.el6 base 143 k
libselinux-devel x86_64 2.0.94-7.el6 base 137 k
libsepol-devel x86_64 2.0.41-4.el6 base 64 k
openssl-devel x86_64 1.0.1e-57.el6 base 1.2 M
perl-DBD-MySQL x86_64 4.013-3.el6 base 134 k
perl-DBI x86_64 1.609-4.el6 base 705 k
zlib-devel x86_64 1.2.3-29.el6 base 44 k Transaction Summary
======================================================
Install 13 Package(s)

###=============================================###

1.2 二进制安装-mysql-5.7.17

1.2.1 准备工作

系统:CentOS 6.9
二进制包: mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz下载到/server/tools/中

1.2.2 解压、移动、授权

cd /server/tools/
tar xf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.17-linux-glibc2.5-x86_64 /application/mysql-5.7.17
ln -s /application/mysql-5.7.17 /application/mysql
#创建用户
useradd -s /sbin/nologin -M mysql #建议指定UID -u 666
#授权
chown -R mysql.mysql /application/mysql-5.7.17

1.2.3 mysql配置

#初始化
/application/mysql-5.7.17/bin/mysqld --initialize --user=mysql --basedir=/application/mysql-5.7.17 --datadir=/application/mysql-5.7.17/data
#记录初始密码(一定要记录此密码)
#此版本与下边5.6版本不一样的地方(不允许空密码登录)
#2017-12-13T11:29:09.168632Z 1 [Note] A temporary password is generated for root@localhost: +u7nkQlqw!4J
#拷贝配置文件和启动文件
cp /application/mysql-5.7.17/support-files/my-default.cnf /etc/my.cnf
cp /application/mysql-5.7.17/support-files/mysql.server /etc/init.d/mysqld
#修改启动文件内容
sed -i 's#/usr/local#/application#g' /application/mysql-5.7.17/bin/mysqld_safe /etc/init.d/mysqld

1.2.4 启动事项

#启动
/etc/init.d/mysqld start
#修改root密码
mysqladmin -uroot -p password ''
#进入mysql (注意:-p后不能直接跟密码,否则登录失败)
[root@lb01 bin]# /application/mysql/bin/mysql -uroot -p
Enter password: 直接粘贴 +u7nkQlqw!4J
#修改密码
[root@lb01 bin]# /application/mysql/bin/mysqladmin -uroot -p password 123456
Enter password: 直接粘贴 +u7nkQlqw!4J
[root@lb01 bin]# ./mysql -uroot -p123456

###=============================================###

1.3 源码安装- mysql-5.6.36.

1.3.1 准备工作

系统:CentOS 6.9

源码包:将安装包mysql-5.6.36.tar.gz下载到/server/tools/中

下载地址: http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36.tar.gz

1.3.2 源码安装前

#安装依赖包
yum install -y ncurses-devel libaio-devel
yum install cmake -y
#创建用户
useradd -s /sbin/nologin -M mysql #建议指定UID -u 666

1.3.3 源码安装

cd /server/tools/
tar xf mysql-5.6.36.tar.gz
cd mysql-5.6.36
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
#注意:-DMYSQL_UNIX_ADDR=/application/mysql-5.6.36/tmp/mysql.sock \
#此版本需要自己创建tmp 目录 mkdir /application/mysql-5.6.36/tmp/

1.3.4 源码安装后

#创建软链接
cd /application/
ln -s /application/mysql-5.6.36/ /application/mysql
cp support-files/my*.cnf /etc/my.cnf
#初始化及配置数据库
/application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data --user=mysql
#授权
chown -R mysql.mysql /application/mysql/
#启动设置
cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 700 /etc/init.d/mysqld
#启动mysql 服务
/etc/init.d/mysqld start

###=============================================###

1.4 优化设置

1.4.1 开机自启

chkconfig mysqld on

1.4.2 加入环境变量

echo 'PATH=/application/mysql/bin/:$PATH' >>/etc/profile
source /etc/profile
mysql

1.4.3 设置密码

mysqladmin -u root password 'oldboy123'

mysql -uroot -poldboy123

1.4.4 清理用户及无用数据库(基本优化)

select user,host from mysql.user;
drop user ''@'db02';
drop user ''@'localhost';
drop user 'root'@'db02';
drop user 'root'@'::1';
select user,host from mysql.user;

本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

上一篇:SSO(单点登录)


下一篇:如何使用adb命令查看android中的数据库