简介
MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司。MySQL 最流行的关系型数据库管理系统,在 WEB 应用方面MySQL是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软件之一。
MySQL是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。
MySQL所使用的 SQL 语言是用于访问数据库的最常用标准化语言。
MySQL 软件采用了双授权政策,它分为社区版和商业版,由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择 MySQL 作为网站数据库。
由于其社区版的性能卓越,搭配 PHP 和 Apache 可组成良好的开发环境
百度百科
环境
初始化系统编译环境 选择合适的MySQL版本进行下载 实验用CentOS 6.7 编译安装 MySQL-5.6.28
MySQL5.7对cmake最低版本要求是2.8.2 如果cmake版本不够 需升级cmake
yum -y install make gcc-c++ gcc cmake bison-devel ncurses-devel perl
软件名称 | 版本号 | 下载地址 |
---|---|---|
mysql | 5.5.47 | 点击下载 |
mysql | 5.6.28 | 点击下载 |
mysql | 5.7.11 | 点击下载 |
步骤
开始编译
MySQL 5.5和5.6版本编译过程差不多 5.7版本开始依赖boost库
链接中5.7的下载地址是已经包含了boost头文件的源码包
1 | tar xf mysql-5.6.28.tar.gz |
配置运行环境
1 | useradd mysql -M -s /sbin/nologin # 创建mysql运行用户 默认同时创建组 |
vim /etc/my.cnf # 修改如下内容
basedir = /usr/local/mysql # mysql基础目录
datadir = /usr/local/mysql/data # mysql数据库目录
port = 3306 # 服务监听端口
启动服务
1 | /etc/init.d/mysqld start |
如果服务启动失败 查看MySQL错误日志
默认路径为:/usr/local/mysql/data/`hostname`.err
输入mysql 查看是否正常连接
[root@8be3d6481fd9 data]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.28 Source distribution
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
MySQL5.7 需要通过这个随机密码登录 而且登录后必须修改密码才能正常使用
[root@8be3d6481fd9 data] # mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.11
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>set password=password('yourpassword');
下次就可以通过新密码登录了 "set password=password('');" 可以配置空密码
附录
MySQL授权远程登录用户 这样就可以在其他主机远程登录MySQL了
grant all privileges on *.* to "user"@"%" identified by "password";
MySQL忘记登录密码处理
先停掉原来的服务 通过跳过授权表 不使用网络连接启动mysql
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
直接通过mysql命令登录 然后修改mysql.user表的信息
update mysql.user set password=password('yourpasswd') where user='root';
MySQL5.7 的密码字段为authentication_string
update mysql.user set authentication_string=password('yourpasswd') where user='root';
通过修改/etc/my.cnf可以修改mysql的数据库目录等位置 修改完数据库位置后可能需要重新初始化数据库