本次 Mysql 为Community 5.6.21 版本,安装方式为通用Linux安装方式,即大多数Linux平台都可以采用该方式进行安装。
一、安装步骤
1、安装环境
1)Centos 7.0.1406 X86_64
2、下载 Mysql 、解压缩、创建软连接,与官方提供解压缩路径有些许。
$ wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz $ sudo tar zxvf mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz -C /usr/local/src/ $ sudo ln -s /usr/local/src/mysql-5.6.21-linux-glibc2.5-x86_64/ /usr/local/mysql
3、安装方式分为两种。
方式1 参考 Mysql 官方指导建议进行安装,多用在Mysql学习环境,下列命令来源Mysql官方,原文参见 Installing MySQL on Unix/Linux Using Generic Binaries
shell> groupadd mysql shell> useradd -r -g mysql mysql shell> cd /usr/local shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz shell> ln -s full-path-to-mysql-VERSION-OS mysql shell> cd mysql shell> chown -R mysql . shell> chgrp -R mysql . shell> scripts/mysql_install_db --user=mysql shell> chown -R root . shell> chown -R mysql data shell> bin/mysqld_safe --user=mysql & # Next command is optional shell> cp support-files/mysql.server /etc/init.d/mysql.server
方式2 自定义 Mysql 数据保存路径,多用在部署环境。
1)创建Mysql用户以及用户组
$ sudo groupadd mysql $ sudo useradd -r -g mysql mysql $ cd /usr/local/src/ $ sudo chown -R mysql:mysql mysql-5.6.21-linux-glibc2.5-x86_64/ #定义mysql用户以及组 $ ll 总用量 4 drwxr-xr-x. 13 mysql mysql 4096 11月 5 08:10 mysql-5.6.21-linux-glibc2.5-x86_64
2)创建Mysql数据文件保存位置,若使用数据盘则自行挂载。
$ sudo mkdir -p /data/mysql #定义mysql数据文件保存地址
3)初始化 Mysql,可能会出现的问题参见文章底部问题处理方法
$ sudo /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/ #初始化 mysql
4)配置 my.cnf
$ sudo vi /usr/local/mysql/my.cnf
本示例仅保证可以正常运行,所以配置如下三项即可。
basedir = /usr/local/mysql datadir = /data/mysql port = 3306
建立软连接 my.cnf 到 /etc/ 目录
$ sudo ln -s /usr/local/mysql/my.cnf /etc/my.cnf
5)启动 Mysql 服务
$ sudo /usr/local/mysql/support-files/mysql.server start Starting MySQL. SUCCESS!
6)登陆 Mysql
$ /usr/local/mysql/bin/mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.21 MySQL Community Server (GPL) Copyright (c) 2000, 2014, 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>
二、开机启动
$ sudo chkconfig --add mysqld
三、环境变量
1)编辑 profile 文件
$ sudo vi /etc/profile
2)添加下列信息到 profile 底部
export PATH=$PATH:/usr/local/mysql/bin
3)立即生效配置文件
$ source /etc/profile
四、Mysql远程连接
mysql> select user(); +----------------+ | user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.01 sec) mysql> grant all privileges on *.* to root@'%' identified by "你的密码"; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
五、防火墙开启
Centos 7 默认启用 firewall 管理端口
1)查看端口开启情况,若之前没有配过会显示 no 说明 3306 端口未开放,反之 yes 说明已开放直接可用 Mysql 客户端远程访问!
$ sudo firewall-cmd --query-port=3306/tcp no
2)临时性开启 3306 端口
$ sudo firewall-cmd --add-port=3306/tcp success
3)永久性开启 3306 端口
$ sudo firewall-cmd --permanent --zone=public --add-port=3306/tcp success $ sudo firewall-cmd --reload #重新加载配置 success [john@localhost ~]$ sudo firewall-cmd --zone=public --list-all #查看添加结果 public (default, active) interfaces: eth0 sources: services: dhcpv6-client ssh ports: 3306/tcp 22/tcp masquerade: no forward-ports: icmp-blocks: rich rules:
六、问题整理
问题1:
$ sudo scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/ sudo: unable to execute scripts/mysql_install_db: No such file or directory
解决:解决这个问题纯属巧合,去掉 sudo 提示 Perl 解析器有问题,重新安装下
$ sudo yum install perl $ sudo yum install perl-Data-Dumper.x86_64
问题2:
$ sudo scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/ Installing MySQL system tables.../usr/local/mysql//bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决:
$ sudo yum install libaio.x86_64
问题3:
$ sudo support-files/mysql.server start Starting MySQL. ERROR! The server quit without updating PID file (/data/mysql/localhost.localdomain.pid).解决:这个问题特别实在首次启动时会提示,简单说就是找不到 my.cnf 文件,将配置完毕 my.cnf 复制到 /etc/ 或 建立软连接到 /etc/ 目录下!
$ sudo cp my.cnf /etc/这里我有点疑惑,表面现象 mysql 启动依赖 /etc/my.cnf 文件,但实际第一次正常启动 mysql 后可以删除 /etc/my.cnf 文件,第二次启动可以正常加载 /usr/local/mysql/my.cnf 文件!
参考文章:
Centos7 安装Mysql 5.6.19
CentOS 7.0编译安装Nginx1.6.0+MySQL5.6.19+PHP5.5.14方法分享
RHEL7中防火墙firewalld的配置(1)

要优化MySQL慢查询,需使用slowquerylog和performance_schema:1.启用slowquerylog并设置阈值,记录慢查询;2.利用performance_schema分析查询执行细节,找出性能瓶颈并优化。

MySQL和SQL是开发者必备技能。1.MySQL是开源的关系型数据库管理系统,SQL是用于管理和操作数据库的标准语言。2.MySQL通过高效的数据存储和检索功能支持多种存储引擎,SQL通过简单语句完成复杂数据操作。3.使用示例包括基本查询和高级查询,如按条件过滤和排序。4.常见错误包括语法错误和性能问题,可通过检查SQL语句和使用EXPLAIN命令优化。5.性能优化技巧包括使用索引、避免全表扫描、优化JOIN操作和提升代码可读性。

MySQL异步主从复制通过binlog实现数据同步,提升读性能和高可用性。1)主服务器记录变更到binlog;2)从服务器通过I/O线程读取binlog;3)从服务器的SQL线程应用binlog同步数据。

MySQL是一个开源的关系型数据库管理系统。1)创建数据库和表:使用CREATEDATABASE和CREATETABLE命令。2)基本操作:INSERT、UPDATE、DELETE和SELECT。3)高级操作:JOIN、子查询和事务处理。4)调试技巧:检查语法、数据类型和权限。5)优化建议:使用索引、避免SELECT*和使用事务。

MySQL的安装和基本操作包括:1.下载并安装MySQL,设置根用户密码;2.使用SQL命令创建数据库和表,如CREATEDATABASE和CREATETABLE;3.执行CRUD操作,使用INSERT,SELECT,UPDATE,DELETE命令;4.创建索引和存储过程以优化性能和实现复杂逻辑。通过这些步骤,你可以从零开始构建和管理MySQL数据库。

InnoDBBufferPool通过将数据和索引页加载到内存中来提升MySQL数据库的性能。1)数据页加载到BufferPool中,减少磁盘I/O。2)脏页被标记并定期刷新到磁盘。3)LRU算法管理数据页淘汰。4)预读机制提前加载可能需要的数据页。

MySQL适合初学者使用,因为它安装简单、功能强大且易于管理数据。1.安装和配置简单,适用于多种操作系统。2.支持基本操作如创建数据库和表、插入、查询、更新和删除数据。3.提供高级功能如JOIN操作和子查询。4.可以通过索引、查询优化和分表分区来提升性能。5.支持备份、恢复和安全措施,确保数据的安全和一致性。

全表扫描在MySQL中可能比使用索引更快,具体情况包括:1)数据量较小时;2)查询返回大量数据时;3)索引列不具备高选择性时;4)复杂查询时。通过分析查询计划、优化索引、避免过度索引和定期维护表,可以在实际应用中做出最优选择。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

记事本++7.3.1
好用且免费的代码编辑器

Dreamweaver CS6
视觉化网页开发工具

Atom编辑器mac版下载
最流行的的开源编辑器

SublimeText3汉化版
中文版,非常好用