1.使用yum安装MySQL在线安装
配置一个安装yum源。
1>
yum install http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
可以手动配置yum源,baseurl指向国内镜像源地址,比如清华、中科大。
/etc/yum.repos.d/mysql.repo
[mysql]
name=mysql5.7
baseurl=http://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/
gpgcheck=0
2> Installing MySQL
yum install mysql-community-server
启动MySQL服务:
# systemctl start mysqld //当前启动
# systemctl enable mysqld //开机自启动
查询临时登录密码:
# awk '/temporary password/ {print $NF}' /var/log/mysqld.log
登录数据库:
# mysql -uroot -p
Enter password:
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
#因为第一次登录需要修改密码才能进行数据库的操作,所以下一步需要修改密码
# 修改密码
mysql> alter user root@localhost identified by '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
# 密码要符合复杂性要求 RedHat@123
mysql> alter user root@localhost identified by 'RedHat@123';
Query OK, 0 rows affected (0.00 sec)
2.使用二进制方式安装MySQL
1> 下载包 --glibc
#在官网下载之后可以使用xftp进行快速拖拽进Linux
ll mysql-5.7.14-linux-glibc2.5-x86_64.tar
-rw-r--r-- 1 root root 672716800 Jul 5 14:15 mysql-5.7.14-linux-glibc2.5-x86_64.tar
2> 创建用户及组
# groupadd -r mysql
# useradd mysql -r -g mysql -c "MySQL Server" -s /bin/false
3> 解压,软链接
# tar xf mysql-5.7.14-linux-glibc2.5-x86_64.tar -C /usr/local
# tar xf /usr/local/mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
创建软链接:为了方便以后升级。
# ln -sv /usr/local/mysql-5.7.14-linux-glibc2.5-x86_64 /usr/local/mysql
‘/usr/local/mysql’ -> ‘/usr/local/mysql-5.7.14-linux-glibc2.5-x86_64’
4> 初始化
# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
5> 提供配置文件和服务启动脚本
# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
修改配置文件:vim /etc/my.cnf
[mysqld]
...
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
# 服务脚本
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
添加系统服务,并设置开机自启动
# chkconfig --add mysqld
# chkconfig mysqld on
6> 启动mysql
# /usr/local/mysql/bin/mysqld_safe --user=mysql &
配置环境变量:
# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
登录MySQL:
bin/mysql -u root -p
修改MySQL的root用户密码:
alter user 'root'@'localhost' identified by 'new_password';
3. 简单描述MySQL的体系结构
连接层:
Connectors:客户端连接器,主要是指不同语言与SQL的交互
服务层:
Enterprise Management Services & Utilities:系统管理和控制工具
Connection Pool:连接池,将用户连接时需要缓存的需求缓存下来,下次可直接连接
SQL Interface:SQL接口,接受用户的SQL命令,并且返回用户需要查询的结果
Parser:解析器,验证和解析SQL命令
Optimizer:查询优化器,在查询前对查询进行优化
Caches & Buffers:查询缓存,若查询缓存中有相应的查询结果,查询语句会直接在查询缓存中读取数据
引擎层:
Pluggable Storage Engines:存储引擎,负责MySQL中数据的存储和提取
存储层:
数据存储层,主要是将数据存储在运行与裸设备的文件系统之上,并完成与引擎层的交互