CentOS 7下安装MySQL

MySQL 是一种关系型数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。MySQL 所使用的 SQL 语言是用于访问数据库的最常用标准化语言。MySQL 软件采用了双授权政策,分为社区版和商业版,由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择 MySQL 作为网站数据库。由于其社区版的性能卓越,搭配 PHP 和 Apache 可组成良好的开发环境。

MySQL安装

el7(CentOS 7)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# rpm -qa | grep -i mysql  //检查是否已安装MySQL,grep的-i选项表示匹配时忽略大小写
# rpm -qa | grep -i mariadb
mariadb-libs-5.5.52-1.el7.x86_64
# rpm -e mariadb-libs-5.5.52-1.el7.x86_64 --nodeps //卸载,–nodeps忽略依赖关系

# wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar
# wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar

# yum install -y perl-Module-Install.noarch numactl libaio
# tar -xf mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar

# rpm -ivh mysql-community-common-5.7.21-1.el7.x86_64.rpm
# rpm -ivh mysql-community-libs-5.7.21-1.el7.x86_64.rpm
# rpm -ivh mysql-community-libs-compat-5.7.21-1.el7.x86_64.rpm
# rpm -ivh mysql-community-client-5.7.21-1.el7.x86_64.rpm //安装mysql客户端
# rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm //安装mysql服务端
# rpm -ivh mysql-community-devel-5.7.21-1.el7.x86_64.rpm

# mysql -V
# vim /etc/my.cnf //配置my.cnf

# systemctl start mysqld //启动MySQL服务
# systemctl status mysqld //查看MySQL运行状态
# systemctl restart mysqld //重启MySQL服务
# grep "password" /var/log/mysqld.log //查看默认root用户密码
# /usr/bin/mysqladmin -uroot -p'YI#O1FgF,ptN' password '123456' //修改root用户密码
# /usr/bin/mysqladmin -u root -h appblog password '123456' //创建数据库

//设置开机启动
# systemctl enable mysqld
# systemctl daemon-reload

el6(CentOS 6)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-5.7.21-1.el6.x86_64.rpm-bundle.tar
# yum install -y perl-Module-Install.noarch numactl libaio
# tar -xf mysql-5.7.21-1.el6.x86_64.rpm-bundle.tar
# rpm -ivh mysql-community-common-5.7.21-1.el6.x86_64.rpm
# rpm -ivh mysql-community-libs-5.7.21-1.el6.x86_64.rpm
# rpm -ivh mysql-community-libs-compat-5.7.21-1.el6.x86_64.rpm
# rpm -ivh mysql-community-client-5.7.21-1.el6.x86_64.rpm
# rpm -ivh mysql-community-server-5.7.21-1.el6.x86_64.rpm
# rpm -ivh mysql-community-devel-5.7.21-1.el6.x86_64.rpm

# service mysqld start //启动MySQL服务
# service mysqld status //查看MySQL运行状态
# service mysqld restart //重启MySQL服务
# grep "password" /var/log/mysqld.log //查看默认root用户密码
# /usr/bin/mysqladmin -uroot -p'YI#O1FgF,ptN' password 'xxxxxx' //修改root用户密码

my.ini配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[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=/data/mysql
socket=/var/lib/mysql/mysql.sock
port=3306

# 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

character_set_server=utf8 #设置MySQL服务器默认字符集
explicit_defaults_for_timestamp=true


[client]
default_character_set=utf8 #设置MySQL客户端默认字符集

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :