一、简介
SQL语言
DDL:表、视图、索引、触发器操作等。CREATE/ALTER/DROP语句
DML:数据操作。SELECT/INSERT/UPDATE/DELETE
DCL:权限设置。GRANT/REVOKE
数据库访问
不同的语言使用不同的数据库访问技术
C#使用ADO.NET,JAVA使用JDBC等
版本
Community Edition:免费、自由下载,无技术支持
Enterprise:收费、不能下载,有技术支持
Alpha:开发阶段
Beta:开发完成,未测试
Gamma:已发行一段时间的测试版
Generally Available(GA):稳定版
工具
MySQL Community Server:客户端和服务器整合起来的核心包
MySQL Cluster:提供Mysql集群功能的程序包
MySQL Fabric:为高可用性和分片管理提供了一个框架
MySQL Utilities:提供维护和管理的实用工具
MySQL Workbench:可视化编辑工具
MySQL Proxy:MySQL中间件,代理接收发往MySQL数据库的请求,将需要求路由至不同的后端主机上去
MySQL Connectors:MySQL的连接器,程序连接MySQL的驱动
MySQL Yum Repository:下载MySQL的YUM源
MySQL APT Repository:APT源
RPM包
MySQL-client:客户端连接工具,GUI工具有navicat、phpmyadmin等
MySQL-server:服务器包
MySQL-devel:库和包含文件
MySQL-shared:某些语言和应用程序需要动态装载的共享库
MySQL-test:测试组件
MySQL-embedded:嵌入式
MySQL-bundle:整合包
相关文件
/etc/my.cnf:配置文件
/usr/share/doc/MySQL-server-5.6.26/my-default.cnf:参考配置文件
/usr/share/mysql/my-default.cnf:同上
/usr/bin:客户端程序和脚本
/usr/sbin mysqld:服务器
/var/lib/mysql:日志文件,数据库
/usr/lib/mysql:数据库
/usr/share/doc/packages:文档
/usr/include/mysql:包含(头)文件
/usr/share/mysql:错误消息和字符集文件
/usr/share/sql-bench:基准程序
二、安装
环境:CentOS 6.7 x86、MySQL 5.6
报错,删除mysql-libs包
[root@CentOS MySQL]# rpm -qa | grep -i mysql
mysql-libs-5.1.73-5.el6_6.i686
[root@CentOS MySQL]# yum remove mysql-libs-5.1.73-5.el6_6.i686
RPM
[root@CentOS MySQL]# rpm -ivh MySQL-server-5.6.26-1.el6.i686.rpm
[root@CentOS MySQL]# rpm -ivh MySQL-client-5.6.26-1.el6.i686.rpm
YUM
[root@CentOS ~]# yum install mysql-server mysql-client
防火墙
[root@CentOS ~]# iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
[root@CentOS ~]# service iptables save
[root@CentOS ~]# service iptables restart
配置
5.1版本root无密码;5.6安装完成后,root生成随机密码在/root/.mysql_secret
5.1有配置文件;5.6无配置文件,需从/usr/share/mysql/my-default.cnf复制到/etc/my.cnf
5.1服务名mysqld,5.6为mysql
开启服务
[root@CentOS ~]# service mysql start
查看登录数据库账号root的密码
[root@CentOS ~]# cat .mysql_secret
# The random password set for the root user at Tue Sep 8 11:26:39 2015 (local time): 4VZTzey0LML2N7e1
初始化设置
[root@CentOS ~]# /usr/bin/mysql_secure_installation --user=mysql
#输入root的密码
Enter current password for root (enter for none):
#是否修改root的密码
Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
#删除匿名用户
Remove anonymous users? [Y/n] y
... Success!
#禁止root远程登录
Disallow root login remotely? [Y/n] y
... Success!
#删除测试数据库
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
#重新加载权限表
Reload privilege tables now? [Y/n] y
... Success!
三、连接数据库
参数:
-h:主机名或IP
-P:端口号,默认3306
-u:用户名
-p:密码
-e:指定SQL语句
[root@CentOS ~]# mysql -u root -p
Enter password:
[root@CentOS ~]# mysql -u root -p db01#连接db01库
[root@CentOS ~]# mysql -h 192.168.41.135 -u root -p#远程连接
四、创建远程用户
user1用户拥有所有权限,%表示任意主机可登录
mysql> create user 'user1'@'%' identified by '123456';
mysql> grant all privileges on *.* to 'user1'@'%';
五、迁移data目录
data目录应独立分区
关闭服务
[root@CentOS ~]# service mysql stop
移动目录
[root@CentOS ~]# mv /var/lib/mysql/ /data/
配置文件
[root@CentOS ~]# cp -a /usr/share/mysql/my-default.cnf /etc/my.cnf
[root@CentOS ~]# vim /etc/my.cnf
datadir=/data/mysql
socket=/data/mysql/mysql.sock
[mysql]
socket=/data/mysql/mysql.sock
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
启动服务
[root@CentOS ~]# service mysql start
SELinux报错解决方法(mv命令保留权限,所以没报错)
[root@CentOS ~]# chcon -R -t mysqld_db_t /data//mysql

In database optimization, indexing strategies should be selected according to query requirements: 1. When the query involves multiple columns and the order of conditions is fixed, use composite indexes; 2. When the query involves multiple columns but the order of conditions is not fixed, use multiple single-column indexes. Composite indexes are suitable for optimizing multi-column queries, while single-column indexes are suitable for single-column queries.

To optimize MySQL slow query, slowquerylog and performance_schema need to be used: 1. Enable slowquerylog and set thresholds to record slow query; 2. Use performance_schema to analyze query execution details, find out performance bottlenecks and optimize.

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

MySQL asynchronous master-slave replication enables data synchronization through binlog, improving read performance and high availability. 1) The master server record changes to binlog; 2) The slave server reads binlog through I/O threads; 3) The server SQL thread applies binlog to synchronize data.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

The installation and basic operations of MySQL include: 1. Download and install MySQL, set the root user password; 2. Use SQL commands to create databases and tables, such as CREATEDATABASE and CREATETABLE; 3. Execute CRUD operations, use INSERT, SELECT, UPDATE, DELETE commands; 4. Create indexes and stored procedures to optimize performance and implement complex logic. With these steps, you can build and manage MySQL databases from scratch.

InnoDBBufferPool improves the performance of MySQL databases by loading data and index pages into memory. 1) The data page is loaded into the BufferPool to reduce disk I/O. 2) Dirty pages are marked and refreshed to disk regularly. 3) LRU algorithm management data page elimination. 4) The read-out mechanism loads the possible data pages in advance.

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.