额,标题是不是很傻逼?
你会安装mysql吗?你真的会吗?windows一键安装除外,给你一台新的linux机子,你打算怎么安装?B度和G哥?
万一搜索的教程是个坑b凑字数写的,你就需要重新安装了,浪费时间,浪费精力。
下面是一休哥自己总结的安装教程,任何新环境,按照步骤安装,一遍过,清新自然,开心的一逼。(注:此次教程环境为centos7,mysql5.6,mysql5.7)
1、卸载系统自带Mariadb
Centos7 已经不自带MySQL,自带内部集成了Mariadb,而安装MySQL的话会和Mariadb的文件冲突,所以需要先卸载掉Mariadb,再安装MySQL。
[root@langer ~]# rpm -qa | grep mariadb // 列出mariadb相关已安装包
mariadb-libs-5.5.40-1.el7_0.x86_64 // 本例中找到的相关RPM包
[root@langer ~]# rpm -e --nodeps mariadb-libs-5.5.40-1.el7_0.x86_64 // 卸载上面找到的所有相关RPM包,格式:rpm -e --nodeps [前面找到的RPM包名]
[root@langer ~]# rpm -qa | grep mariadb // 在卸载完以后再次用此命令来查看
[root@langer ~]# // 未查找到,表明mariadb已经卸载成功!!
2、准备MySQL安装包
我们需要MySQL的如下包:
下载地址
mysql-community-server-5.7.20-1.el7.x86_64.rpm
mysql-community-client-5.7.20-1.el7.x86_64.rpm
mysql-community-libs-5.7.20-1.el7.x86_64.rpm
mysql-community-common-5.7.20-1.el7.x86_64.rpm
3、开始安装MySQL
按下面顺序依次安装:
[root@langer ~]# yum install -y perl-Module-Install.noarch
[root@langer ~]# yum -y install perl
[root@langer ~]# yum -y install libaio // CentOS7最小版本安装MySQL找不到Perl的依赖包的解决办法,或MySQL通过rpm包方式安装时,不会执行mysql_install_db从而生成/root/.mysql_secret等,是缺少上面这3个依赖,所以我们先装下(如果已有会提示你无需安装),以免安装过程出错要卸载重装更麻烦。
[root@langer ~]# yum install libnuma*
[root@langer ~]# cd /data/resource // 进入AtlassianResource目录下
[root@langer resource]# rpm -ivh mysql-community-common-5.7.20-1.el7.x86_64.rpm
[root@langer resource]# rpm -ivh mysql-community-libs-5.7.20-1.el7.x86_64.rpm
[root@langer resource]# rpm -ivh mysql-community-client-5.7.20-1.el7.x86_64.rpm
[root@langer resource]# rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
[root@langer resource]# // 安装成功
[root@langer ~]# service mysqld start // 启动命令
[root@langer ~]# systemctl start mysqld // 或用此命令启动
[root@langer ~]# cat /var/log/mysqld.log |grep password //用此命令查看生成的临时密码,如下面的密码为mWoe;zkj4M3
2017-12-13T10:50:44.960028Z 1 [Note] A temporary password is generated for root@localhost: =mWoe;zkj4M3
至此,安装过程完成。
4、配置MySQL
初次登录,修改登录密码。(不改的话,不能用root用户创建新库、查询数据等)
[root@langer ~]# mysql -u root -p // 登录命令
Enter password:
mysql> SET PASSWORD = PASSWORD('nooMkf.86'); // 登录成功后设置新密码,密码要求含有大小写、数字、一些特殊字符(如,./等)。
mysql> exit // 退出MySQL
Bye
[root@langer ~]#
修改MySQL my.cnf配置文件(下面是经验的参数,按个人需求)
[root@langer ~]# service mysqld stop // 先停止MySQL服务
[root@langer ~]# vi /etc/my.cnf // 编辑my.cnf配置文件,下文中标"[###]"的行为添加或修改过的配置
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysql] // [###]
default-character-set=utf8mb4 // [###]
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
transaction-isolation = READ-COMMITTED // [###]
max_allowed_packet=256M // [###]
innodb_log_file_size=2G // [###]
innodb_buffer_pool_size=512M // [###]
innodb_file_per_table=1 // [###]
collation-server=utf8mb4_unicode_ci // [###]
character_set_server=utf8mb4 // [###]
default-storage-engine=INNODB // [###]
innodb_default_row_format=DYNAMIC // [###]
innodb_large_prefix=ON // [###]
innodb_file_format=Barracuda // [###]
binlog_format=row // [###]
performance_schema_max_table_instances=400 // [###] 此行和下面两行配置,添加后,若MySQL无法启动,则请删除;若可正常启动,则最好添加上。
table_definition_cache=400 // [###]
table_open_cache=256 // [###]
[root@langer mysql]# cd /var/lib/mysql/ // 进入这个目录,ls下我们可看到两个文件ib_logfile0和ib_logfile1
[root@langer mysql]# rm -rf ib_logfile* // 删除这两个文件
[root@langer mysql]# service mysqld start // 重新启动MySQL服务,后面看配置是否生效
[root@langer mysql]# mysql -u root -p // 登录MySQL
Enter password:
mysql> show VARIABLES like '%max_allowed_packet%'; // 查看最大包限制大小
+--------------------------+------------+
| Variable_name | Value |
+--------------------------+------------+
| max_allowed_packet | 268435456 |
| slave_max_allowed_packet | 1073741824 |
+--------------------------+------------+
2 rows in set (0.00 sec)
mysql> SHOW VARIABLES LIKE 'character%'; // 查看字符集变量
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
mysql> // 看到上面这些配置,表示我们前面修改的配置已经生效了。
5、创建数据库
mysql> CREATE DATABASE hipchatdb CHARACTER SET utf8 COLLATE utf8_bin; // 用此命令创建HipChat数据库,其中"hipchatdb"为库名
mysql> show databases; // 显示当前数据库
+--------------------+
| Database |
+--------------------+
| information_schema | |
| hipchatdb |
| mysql |
| performance_schema |
+--------------------+
至此,数据库这边就已经部署完毕,准备就绪。。。
下次见啦~