MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。在存储引擎方面,使用XtraDB(英语:XtraDB)来代替MySQL的InnoDB。
首先我们来回顾下代理的概念,所谓代理就是指的是一端面向客户端,另外一端面向服务端,代理客户端访问服务端,我们把这种代理叫正向代理;代理服务端响应客户端我们叫做反向代理,这个我们在之前nginx系列博客
mariadb的主从复制集群,默认情况下是把主库上的所有库进行复制,只要在主库上产生写操作,从库基于主库的二进制日志做重放,从而实现把主库的上的库表复制到从库;复制过滤器指的是我们仅复制一个或几个数据
首先我们来了解下在mariadb/mysql数据库主从复制集群中什么是同步,什么是异步,什么是半同步;所谓同步就是指主节点发生写操作事件,它不会立刻返回,而是等到从节点接收到主节点发送过来的写操作事件
上一篇我们聊到了mariadb的锁,以及怎么手动加锁和解锁等等,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/13196905.html;今天我们来聊一聊mar
前面我们聊到了mariadb的事务,以及事务隔离级别,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/13198186.html;今天我们来聊一聊mariadb的
首先我们来看看mariadb的锁定概念,所谓锁就是当一个进程或事务在操作某一资源时,为了防止其他用户或者进程或事务对其进行资源操作,导致资源抢占而发生冲突,通常在A进程操作该资源时,会对该资源进行加锁
1、编写脚本,支持让用户自主选择,使用mysqldump还是xtraback全量备份。 [root@test-centos7-node1 scripts]# cat chose_backup_mysq
问题描述vagrant@homestead:~/Code/zookeeper-3.4.9/bin$ sudo mysql -uroot -p Enter password:ERROR 1045 (28000): Access denied for user 'r
## 1 安装Mariadb > 使用默认的 `yum install mariadb-server`时,默认安装的是和Mysql相兼容的5.5版本。想要安装更高的版本,必须先指定yum源。 ### 1.1 使用源配置向导 [配置向导](https://downloads.mariadb.org/mariadb/repositories): https://downloads.mariadb.org/mariadb/repositories 可以选择合适的操作系统...
停止mysql服务在mysql配置文件里[mysqld]下添加skip-grant-tables3.重启服务,进入mysql4.修改密码:MariaDB [mysql]> update mysql.user set password=PASSWORD('123456') where User='root';MariaDB [(none)]> flush privileges;成功后,退出,注释掉刚才的配置文件,重启服务。
原文:http://www.ibm.com/developerworks/library/os-beyondmysql/IntroductionMySQL is one of the most popular free and open source programs in history. It's the database backbone for thousands of websites and could arguably be given credit (along with Linux®) for the explosive growth of the Internet over the past 10 years.So, if MySQL is so important, why is increasing amount of high profile off-shoots of the core MySQL product? Because MySQL is free and open source, developers have always been able to take the code, modify it as they see fit, and distribute it on their own. For a long time, there weren't any branches of MySQL that a developer would trust in their own production environment. However, that's changing rapidly. Several branches are getting a lot of attention.This article will discuss three popular branches of MySQL that are gaining attention: Drizzle, MariaDB, and Percona Server, including the XtraDB engine. This article will talk briefly about the reasons for each branch and their goals, and whether to use them in your own production environment. By the time you finish this article, you should be able to answer the question "Are these MySQL branch products a good solution for my environment?"Why branch?Why does MySQL need to be branched? That's a very legitimate question. Thousands of websites depend on it and it seems to be a good solution for many people. However, as is often the case, what's good for many people isn't good for all people. Some developers are motivated to make things better for their own needs. What could be better than turning a great solution into the perfect solution?Let's get into more specific details about what these branches sought to change. Some branches felt that MySQL was becoming too bloated and was offering many features that would never interest users, at the expense of simplicity of performance. If people were perfectly happy with the more streamlined MySQL 4, why should they deal with the additional complexity that was added with MySQL 5? For this branch, a preferred branch of MySQL would be simpler and faster — offer less features, but make them extremely quick, keeping in mind a target audience, in this case high availability websites.To other branches, MySQL wasn't offering enough new features, or were adding them too slowly. They may have felt that MySQL wasn't keeping up with its target markets of high availability websites running on multi-core processors with lots of RAM. As people familiar with MySQL know, it offers two different storage enginges — MyISAM and InnoDB. This branch felt that neither of these storage engines offered them exactly what they were looking for, so they created a new storage engine perfectly suited for their goals.Further, some branches have a top goal to be a "drop in" replacement to MySQL, where you could simply drop in their branch and not have to change one line of code. The branch uses the same code and interfaces as MySQL, making a transition as easy as possible. Yet, another branch boasts that it's not compatible with MySQL, requiring code changes. Each branch is also at a different maturity level, with some claiming they are production ready, and some claiming they are far from that goal at this point.Finally, there's uncertainty about how MySQL will fare under Oracle. Oracle bought Sun, who bought MySQL, and right now Oracle controls the MySQL product itself, and leads the development community in producing new finished products. Because Oracle already has a commercial database, there is concern that they may not put sufficient resources into MySQL to keep it cutting-edge. Therefore, many branches are also a result of the underlying fear that MySQL, the leading free and open source database, may see less features, slower release cycles, and more expensive support.XtraDBXtraDB is not a stand-alone product itself, but it is still considered a branch of MySQL. XtraDB is actually a storage engine for MySQL-based databases. This would be considered an additional storage engine to the standard MyISAM and InnoDB that are already a part of MySQL. MySQL 4 and 5 installs with each table using the default MyISAM storage engine. InnoDB is also a relatively newer option for a storage engine, and database administrators and developers can choose the types of storage engine, on a per table basis, when they set up the database. The major difference between the two storage engines is that MyISAM does not offer transactional support, while InnoDB does. Other differences are many small performance differences, with InnoDB offering many small performance improvements over MyISAM, and more reliability and safety when dealing with potential data loss. As it appears that InnoDB is the better-suited storage engine for future improvements, MySQL has switched the default storage engine to InnoDB instead of MyISAM starting with the 5.5 release.Building on these advantages, the InnoDB storage engine itself has been branched into a newer storage engine called XtraDB. Just how new is this storage engine? It was
原文地址:http://mysql.rjweb.org/doc.php/ricksrotsBrought to you by Rick JamesHere are 160+ tips, tricks, suggestions, etc. They come from a decade of improving performance in MySQL in thousands of situations. There are exceptions to the statements below, but they should help guide you into better understanding how to effectively use MySQL. SELECTs -- do's and don'tsRoTsDiscussion    ⚈  Do not hide an indexed column inside a function call: DATE(x) = '...', LCASE(col) = 'foo'     ⚈  LCASE() is usually unnecessary because the collation will compare 'correctly' without it.     ⚈  #1: Subqueries perform poorly     ⚈  Never use "IN (SELECT...)" -- optimizes poorly. Turn into JOIN. (5.6.5 improves)     ⚈  A subquery that condenses data (GROUP BY, LIMIT, etc) may perform well     ⚈  OR may be very inefficient; turn into UNION.     ⚈  A coding pattern: dt >= '2010-02-01' AND dt < '2010-02-01' + INTERVAL 7 DAY     ⚈  ORDER BY NULL -- a little-known trick to avoid GROUP BY doing a sort (if there is another way).     ⚈  WHERE (a,b) > (7,8) is poorly optimized     ⚈  Gather these to study a slow query: SHOW CREATE TABLE, SHOW TABLE STATUS, EXPLAIN.     ⚈  Do not use OFFSET for pagination -- continue where you "left off"     ⚈  Don't mix DISTINCT and GROUP BY     ⚈  Be explicit about UNION ALL vs UNION DISTINCT -- it makes you think about which to use     ⚈  Do not use SELECT * except for debugging or when fetching into a hash.     ⚈  VIEWs are poorly optimized     ⚈  A subquery in the FROM clause may be useful for retrieving BLOBs without sorting them: Speed up a query by first finding the IDs, then self-JOIN to fetch the rest. Subqueries came to MySQL rather late in the game. They have not been well optimized, so it is usually better to turn your SELECTs into an equivalent JOIN. This is especially true for "IN ( SELECT ... )", but that is better optimized in 5.6.5 and MariaDB 5.5. Sometimes a subquery is really the best way to optimize a SELECT. The common thread of these "good" subqueries seems to be when the subquery has to scan a lot of rows, but boils down the intermediate resultset to a small number of rows. This is likely to happen with GROUP BY or LIMIT in the subquery. Index hints (FORCE INDEX, etc) may help you today, but may be the wrong thing for tomorrow -- different constants in the WHERE clause may lead FORCE to do the "wrong" thing. For analyzing a slow query, SHOW CREATE TABLE provides the datatypes, indexes, and engine. (DESCRIBE provides much less info.) SHOW TABLE STATUS tells how big the table is. EXPLAIN says how the query optimizer decided to perform the query. It is so tempting to use ORDER BY id LIMIT 30,10to find the 4th page of 10 items. But it is so inefficient, especially when you have thousands of pages. The thousandth page has to read (at some level) all the pages before it. "Left off" refers to having the "Next" button on one page give the id (or other sequencing info) of where the next page can be found. Then that page simply does WHERE id > $leftoff ORDER BY id LIMIT 10. More on pagination.INDEXingRoTsDiscussion    ⚈  #1: Start an INDEX with "="s from the WHERE clause, then one other thing (range, group, order)     ⚈  Terms: PRIMARY KEY > UNIQUE > INDEX = KEY     ⚈  An index _may_ speed up a SELECT by orders of magnitude and will slow down INSERTs a little. (A fair tradeoff?)     ⚈  Adding indexes is not a panacea.     ⚈  BTree is an excellent all-around indexing mechanism     ⚈  A BTree index node contains ~100 items. (1M rows = 3 levels; 1B rows = 5 levels)     ⚈  Flags, and other fields with few values, should not be alone in an index -- the index won't be used.     ⚈  MySQL rarely uses two INDEXes in one SELECT. Main exceptions: subqueries, UNION.     ⚈  A "prefix" index -- INDEX(name(10)) -- is rarely useful. Exception: TEXT     ⚈  A UNIQUE "prefix" is probably wrong -- UNIQUE(name(10)) forces 10 chars to be unique.     ⚈  It is ok to have Index_length > Data_length     ⚈  5 fields in a compound index seems "too many"     ⚈  Having no compound indexes is a clue that you do not understand their power. INDEX(a,b) may be much better than INDEX(a), INDEX(b)     ⚈  INDEX(a,b) covers for INDEX(a), so drop the latter.     ⚈  2x speedup when "Using index" (a "covering" index)     ⚈  Akiban (3rd party) "groups" tables together, interleaved, to improve JOIN performance.     ⚈  FULLTEXT (MyISAM) -- watch out for ft_min_word_len=4, stopwords, and 50% rule     ⚈  A FULLTEXT index will be used before any other index.     ⚈  FULLTEXT -- consider Syphinx, Lucene, etc (3rd Party) Indexing is very important to any database. Getting the "right" index can make a query run orders of magnitude faster. So, how to do that? Often "compound indexes" (multiple columns in a single INDEX(...)) are better than single-column indexes. A WHERE clause that has column=constant begs for an index that starts with that column. If the WHERE
最近把之前学生时代的win server换成了linux(centos)系统,因为win对于部署一些项目时候比较麻烦,直接入正题 1、准备阶段我使用xshell工具管理服务器,相应下载和安装自行百度 2、安装接下来主要介绍Linux下使用yum安装MySQL,以及启动、登录和远程访问MySQL数据库。2.1安装mysql客户端yum install mysql如何出现下面这个,说明,已经安装了mysql 2.2安装mysql服务端yum install mysql-serveryum install mysql-devel在CentOS7上用上面的命令安装mysql服务端时,出现了以下的提示:原因是:CentOS7带有MariaDB而不是MySQL,MariaDB和MySQL一样也是开元的数据库,您可以使用yum -y install mariadb-server mariadb命令安装 解决方案:如果必须要安装MySQL,首先必须添加mysql社区repo通过输入命令:sudo rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm最后使用像安装MySQL的常规方法一样输入上面两行命令安装既可 2.3启动和停止1、数据库字符集设置,mysql配置文件/etc/my.cnf中加入default-character-set=utf82、启动mysql服务service mysqld start或者/etc/init.d/mysqld start 3、检查是否成功启动了mysql 4、停止mysqlservice mysqld stop 5、开机启动chkconfig -add mysqldchkconfig --list | grep mysql* //查看开机启动设置是否成功mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭  2.4登录 1、创建root管理员mysqladmin -u root password 1234561.1创建普通用户 create user 用户名 identified by '密码';例:create user xiaogang identified by '123456'; 2、登陆mysql -u root -p输入密码即可。 3、忘记密码service mysqld stopmysqld_safe --user=root --skip-grant-tablesmysql -u rootuse mysqlupdate user set password=password("new_pass") where user="root";flush privileges; 2.5远程登陆开放防火墙的端口号1、为需要远程登录的用户赋予权限如何给用户分配权限grant 权限 on 数据库.数据表 to '用户' @ '主机名';(1)支持root用户允许远程连接mysql数据库grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;flush privileges;注意:root就拥有了所有的权限 (2)新建用户远程连接mysql数据库grant all on *.* to admin@'%' identified by '123456' with grant option;flush privileges;允许任何ip地址(%表示允许任何ip地址)的电脑用admin帐户和密码(123456)来访问这个mysql server。注意admin账户不一定要存在。注意:admin用户就拥有了所有的权限 (3)让 saucxs有查询 weekly数据库week_week 表的权限;grant select on weekly.week_week to 'saucxs'@'%'; (4)让saucxs有增删改查weekly数据库所有表的数据权限grant select,insert,update,delete on weekly.* to 'saucxs'@'%';注意:这个只有删除表中数据增删改查,而不是表的增删改查下面是我要进行建表操作,被拒绝了 (5)给电脑IP为10.163.225.87的用户saucxs分配可对数据库weekly的week_week表进行select,insert,update,delete,create,drop等操作的权限,并设定口令为123456。这样做的目的是只有在指定的电脑指定IP上才能登陆这个数据库账号。grant select,insert,update,delete,create,drop on weekly.week_week to saucxs@10.163.225.87;注意:这个create和drop 是指的数据库表的创建和删除,而不是数据表中数据新增和删除。 (6)如何收回mysql分配给别的用户的权限,一般指有root用户才具有该权限revoke 权限 on 数据库.数据表 from '用户'@'主机名'; 举个例子,回收查询功能,这样查询功能就失效了revoke select on weekly.* from 'saucxs'@'%'; (7)查看端口show global variables like 'port' centos7.x已经把3306端口开放了,并且不需要开启防火墙,直接用就行 
MySQL(MariaDB)一,说明MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。也就是说MySQL即将要收费MariaDB是完全兼容MySQL的,包括API和命令行,使之能轻松成为MySQL的代替品。Red Hat Enterprise Linux/CentOS 7.0 发行版已将默认的数据库从 MySQL 切换到 MariaDB。二,添加 MariaDB yum 仓库当前环境:阿里云的yum源直接 yum install mariadb 发现版本特别低,还是5.5版本的,官方已经推出10.1版本了按照程序员的尿性,当然是下载官方最新版啦~# 首先在 RHEL/CentOS 和 Fedora 操作系统中添加 MariaDB 的 YUM 配置文件 MariaDB.repo 文件。mkdir mariadb.repo# 然后编辑创建mariadb.repo仓库文件vi /etc/yum.repos.d/MariaDB.repo# 再输入 i 进入编辑模式,添加repo仓库配置[mariadb]name = MariaDBbaseurl = http://yum.mariadb.org/10.1/centos7-amd64gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDBgpgcheck=1这里吐槽一波~官方服务器在国外,下载忒慢了!!三,安装MariaDB# 当 MariaDB 仓库地址添加好后,你可以通过下面的一行命令轻松安装 MariaDB。yum install MariaDB-server MariaDB-client -y启动MariaDB相关命令systemctl start mariadb #启动MariaDBsystemctl stop mariadb #停止MariaDBsystemctl restart mariadb #重启MariaDBsystemctl enable mariadb #设置开机启动四,初始化MariaDB在确认 MariaDB 数据库软件程序安装完毕并成功启动后请不要立即使用。为了确保数据 库的安全性和正常运转,需要先对数据库程序进行初始化操作。这个初始化操作涉及下面 5 个 步骤。➢ 设置 root 管理员在数据库中的密码值(注意,该密码并非 root 管理员在系统中的密 码,这里的密码值默认应该为空,可直接按回车键)。➢ 设置 root 管理员在数据库中的专有密码。➢ 随后删除匿名账户,并使用 root 管理员从远程登录数据库,以确保数据库上运行的业务的安全性。➢ 删除默认的测试数据库,取消测试数据库的一系列访问权限。➢ 刷新授权列表,让初始化的设定立即生效。注意: 确保mariadb服务器启动后,执行命令初始化mysql_secure_installation然后就是一路 Y 到底了。你也可以按照自己的需求进行配置 如:出现 Disallow root login remotely? [Y/n]  --> 禁止root用户从远程登录, 可以选<n>呀 !五,设置MariaDB支持中文MariaDB跟MySQL一样,数据库格式是拉丁文的,默认不支持中文我们得把它的数据格式改成 utf-8# 打开配置文件vim /etc/my.cnf# 先 dG 清空文件夹。没清空就按 g 回到首行, 再 dG 清空# 再按 i 进入编辑模式 复制如下代码[mysqld]character-set-server=utf8collation-server=utf8_general_cilog-error=/var/log/mysqld.logdatadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0# Settings user and group are ignored when systemd is used.# If you need to run mysqld under a different user or group,# customize your systemd unit file for mariadb according to the# instructions in http://fedoraproject.org/wiki/Systemd[client]default-character-set=utf8[mysql]default-character-set=utf8[mysqld_safe]log-error=/var/log/mariadb/mariadb.logpid-file=/var/run/mariadb/mariadb.pid## include all files from the config directory#!includedir /etc/my.cnf.d# 最后 按 Esc 键,进入命令模式, :wq! 保存强制退出就怕你忘记vim怎么操作了, 所以步骤都在里面了!贴心吧~六,登录注意:登录前先重启数据库systemctl restart mariadbmysql -uroot -p # 你没看错,这条就是登录命令# 登录后MariaDB [(none)]> s # 查看编码设置其它命令跟MySQl都一模一样不懂就去看我这篇MySQL的博客吧 redis安装一,yum安装#前提得配置好阿里云yum源,epel源#查看是否有redis包yum list redis#安装redisyum install redis -y#安装好,启动redissystemctl start redis没配置源的也还有两个方案:方案一:去看我上篇博客,配置国内源方案二:继续往下看 ⬇检查redis是否工作redis-cli #redis 客户端工具#进入交互式环境后,执行ping,返回pong表示安装成功127.0.0.1:6379> pingPONG二,源码编译安装redis# 1.下载redis源码, 可以 cd /opt 下载到此目录wget http://download.redis.io/releases/redis-4.0.10.tar.gz# 2.解压缩tar -zxf redis-4.0.10.tar.gz# 3.切换redis源码目录cd redis-4.0.10# 4.编译源文件make && make install# 5.启动redis服务端./redis-serverredis可执行文件的说明./redis-benchmark # 用于进行redis性能测试的工具./redis-check-dump #用于修复出问题的dump.rdb文件./redis-cli # redis的客户端./redis-server # redis的服务端./redis-check-aof # 用于修复出问题的AOF文件./redis-sentinel # 用于集群管理默认情况下,redis-server会以非daemon的方式来运行,且默认服务端口为6379。到这里,redis就可以正常运行啦~下面是关于安全方面的~三,切换redis端口目的:由于redis端口默认都是 6379,黑客可以利用这一点侵入你服务器,所以得换一个让它们想不到的端口来运行 redis再一个就是配置了redis以后,启动redis-server服务端得时候就不会默认挂载在哪里了, 它会在后台运行服务端, 你就可以不需要另外切换窗口去运行客户端了。# 1. 先切换到目标目录cd /opt/redis-4.0.10/# 2. 创建文件touch redis-6380.conf# 3. 创建文件夹mkdir 6380# 4. 打开这个文件vi /opt/redis-4.0.10/redis-6380.conf# 5. 按 i 进入编辑默认,复制下面代码port 6380 # 运行在6380的redis数据库实例daemonize yes # 后台运行redispidfile /opt/redis-4.0.10/6380/redis.pid # 存放redis pid的文件loglevel notice # 日志等级logfile "/opt/redis-4.0.10/6380/redis.log" # 指定redis日志文件的生成目录dir /opt/redis-4.0.10/6380 # 指定redis数据文件夹的目录protected-mode yesrequirepass 123 # 设置redis的密码,密码自己改# 然后 按 Esc 键,进入命令模式,输入 :wq! 保存并强制退出# 为了兼容性,复制的时候还是把注释删了把!!!你也可以根据自己的需求配置文件路径~此时启动redis服务端命令就变成这样了redis-server redis-6380.conf启动客户端命令也变了redis-cli -p 6380 -a 123# -p 设置redis链接的端口# -a 显示填写的密码# 或者redis-cli -p 6380auth 123注意: 启动以后先 ping 一下, 没显示 PONG,就说明没连接成功
一,存储引擎介绍存储引擎即表类型,mysql根据不同的表类型会有不同的处理机制详见:https://www.cnblogs.com/peng104/p/9751738.html 二,表介绍表相当于文件,表中的一条记录就相当于文件的一行内容,不同的是,表中的一条记录有对应的标题,称为表的字段id,name,qq,age称为字段,其余的,一行内容称为一条记录 三,创建表create table 表名(字段名1 类型[(宽度) 约束条件],字段名2 类型[(宽度) 约束条件],字段名3 类型[(宽度) 约束条件]);#注意:1. 在同一张表中,字段名是不能相同2. 宽度和约束条件可选3. 字段名和类型是必须的MariaDB [(none)]> create database db1 charset utf8;MariaDB [(none)]> use db1;MariaDB [db1]> create table t1(-> id int,-> name varchar(50),-> sex enum('male','female'),-> age int(3)-> );MariaDB [db1]> show tables; #查看db1库下所有表名MariaDB [db1]> desc t1;+-------+-----------------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+-------+-----------------------+------+-----+---------+-------+| id | int(11) | YES | | NULL | || name | varchar(50) | YES | | NULL | || sex | enum('male','female') | YES | | NULL | || age | int(3) | YES | | NULL | |+-------+-----------------------+------+-----+---------+-------+MariaDB [db1]> select id,name,sex,age from t1;Empty set (0.00 sec)MariaDB [db1]> select * from t1;Empty set (0.00 sec)MariaDB [db1]> select id,name from t1;Empty set (0.00 sec)View CodeMariaDB [db1]> insert into t1 values-> (1,'egon',18,'male'),-> (2,'alex',81,'female')-> ;MariaDB [db1]> select * from t1;+------+------+------+--------+| id | name | age | sex |+------+------+------+--------+| 1 | egon | 18 | male || 2 | alex | 81 | female |+------+------+------+--------+MariaDB [db1]> insert into t1(id) values-> (3),-> (4);MariaDB [db1]> select * from t1;+------+------+------+--------+| id | name | age | sex |+------+------+------+--------+| 1 | egon | 18 | male || 2 | alex | 81 | female || 3 | NULL | NULL | NULL || 4 | NULL | NULL | NULL |+------+------+------+--------+View Code注意:表中的最后一个字段不要加逗号  四,查看表结构MariaDB [db1]> describe t1; #查看表结构,可简写为desc 表名+-------+-----------------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+-------+-----------------------+------+-----+---------+-------+| id | int(11) | YES | | NULL | || name | varchar(50) | YES | | NULL | || sex | enum('male','female') | YES | | NULL | || age | int(3) | YES | | NULL | |+-------+-----------------------+------+-----+---------+-------+MariaDB [db1]> show create table t1G; #查看表详细结构,可加G 五,数据类型详见:https://www.cnblogs.com/peng104/p/9757047.html 六,表的完整性约束待更。。 七,修改表语法:1. 修改表名ALTER TABLE 表名RENAME 新表名;2. 增加字段ALTER TABLE 表名ADD 字段名 数据类型 [完整性约束条件…],ADD 字段名 数据类型 [完整性约束条件…];ALTER TABLE 表名ADD 字段名 数据类型 [完整性约束条件…] FIRST;ALTER TABLE 表名ADD 字段名 数据类型 [完整性约束条件…] AFTER 字段名;3. 删除字段ALTER TABLE 表名DROP 字段名;4. 修改字段ALTER TABLE 表名MODIFY 字段名 数据类型 [完整性约束条件…];ALTER TABLE 表名CHANGE 旧字段名 新字段名 旧数据类型 [完整性约束条件…];ALTER TABLE 表名CHANGE 旧字段名 新字段名 新数据类型 [完整性约束条件…];示例:1. 修改存储引擎mysql> alter table service-> engine=innodb;2. 添加字段mysql> alter table student10-> add name varchar(20) not null,-> add age int(3) not null default 22;mysql> alter table student10-> add stu_num varchar(10) not null after name; //添加name字段之后mysql> alter table student10-> add sex enum('male','female') default 'male' first; //添加到最前面3. 删除字段mysql> alter table student10-> drop sex;mysql> alter table service-> drop mac;4. 修改字段类型modifymysql> alter table student10-> modify age int(3);mysql> alter table student10-> modify id int(11) not null primary key auto_increment; //修改为主键5. 增加约束(针对已有的主键增加auto_increment)mysql> alter table student10 modify id int(11) not null primary key auto_increment;ERROR 1068 (42000): Multiple primary key definedmysql> alter table student10 modify id int(11) not null auto_increment;Query OK, 0 rows affected (0.01 sec)Records: 0 Duplicates: 0 Warnings: 06. 对已经存在的表增加复合主键mysql> alter table service2-> add primary key(host_ip,port);7. 增加主键mysql> alter table student1-> modify name varchar(10) not null primary key;8. 增加主键和自动增长mysql> alter table student1-> modify id int not null primary key auto_increment;9. 删除主键a. 删除自增约束mysql> alter table student10 modify id int(11) not null;b. 删除主键mysql> alter table student10-> drop primary key;示例 八,复制表复制表结构+记录 (key不会复制: 主键、外键和索引)mysql> create table new_service select * from service;只复制表结构mysql> select * from service where 1=2; //条件为假,查不到任何记录Empty set (0.00 sec)mysql> create table new1_service select * from service where 1=2;Query OK, 0 rows affected (0.00 sec)Records: 0 Duplicates: 0 Warnings: 0mysql> create table t4 like employees; 九,删除表DROP TABLE 表名;  总述:启动masqlmysql start mysql ;查看当前登陆的用户select user();查看所有的库show databases;退出当前客户端exit 或 q用户名root登陆mysql -uroot -p;放弃本条语句c设置密码set password = password("123");创建用户create user 'alex
一、LNMP的安装##先要下载,并根据不同系统进行安装:wget -c http://soft.vpser.net/lnmp/lnmp1.5.tar.gztar zxvf lnmp1.5.tar.gzcd lnmp1.5./install.sh #开始进行安装操作以上为下载及进入安装过程,以下为安装前简易设置,切记输入个其它域名及牢记mysql密码:+------------------------------------------------------------------------+| LNMP V1.5 for CentOS Linux Server, Written by Licess |+------------------------------------------------------------------------+| A tool to auto-compile & install LNMP/LNMPA/LAMP on Linux |+------------------------------------------------------------------------+| For more information please visit https://lnmp.org |+------------------------------------------------------------------------+You have 10 options for your DataBase install.1: Install MySQL 5.1.732: Install MySQL 5.5.60 (Default)3: Install MySQL 5.6.404: Install MySQL 5.7.225: Install MySQL 8.0.116: Install MariaDB 5.5.607: Install MariaDB 10.0.358: Install MariaDB 10.1.339: Install MariaDB 10.2.140: DO NOT Install MySQL/MariaDBEnter your choice (1, 2, 3, 4, 5, 6, 7, 8, 9 or 0): #选择mysql版本 默认为5.5.60No input,You will install MySQL 5.5.60===========================Please setup root password of MySQL.Please enter: vpsmm.com #输入mysql的密码===========================Do you want to enable or disable the InnoDB Storage Engine?Default enable,Enter your choice [Y/n]: n #是否安装InnoDB环境 默认不需要 whmcs之类特殊程序需求You will disable the InnoDB Storage Engine!===========================You have 8 options for your PHP install.1: Install PHP 5.2.172: Install PHP 5.3.293: Install PHP 5.4.454: Install PHP 5.5.385: Install PHP 5.6.36 (Default)6: Install PHP 7.0.307: Install PHP 7.1.188: Install PHP 7.2.6Enter your choice (1, 2, 3, 4, 5, 6, 7 or 8): 8 #默认php版本 这里选择最新You will install PHP 7.2.6===========================You have 3 options for your Memory Allocator install.1: Don't install Memory Allocator. (Default)2: Install Jemalloc3: Install TCMallocEnter your choice (1, 2 or 3): 1 这个默认选择不安装即可You will install not install Memory Allocator.#按任意键,设置完成,正式进入安装,预计20-40分钟完成常见lnmp管理命令:#1.2版本以后,不需要再执行/root/lnmp了,可以在任意位置执行lnmp命令lnmp #会出现一些提示信息lnmp restart #重启lnmp vhost add #添加网站绑定lnmp database add #添加数据库信息二,域名绑定详解其实所谓的域名绑定,就是通过命令的形式,简易创建一个conf文件到/usr/local/nginx/conf/vhost下面,这个过程完全可以手工创建conf,或者,平时修改目录、域名等,直接修改conf文件,效果完全一样:lnmp vhost add #执行lnmp添加网站命令+-------------------------------------------+| Manager for LNMP, Written by Licess |+-------------------------------------------+Please enter domain(example: www.lnmp.org): vpsmm.com #输入绑定的主域名======================================Your domain: vpsmm.com======================================Do you want to add more domain name? (y/n) y #是否绑定其它域名Enter domain name(example: lnmp.org *.lnmp.org): www.vpsmm.com #输入其它域名domain list: www.vpsmm.comPlease enter the directory for the domain: vpsmm.com(Default directory: /home/wwwroot/vpsmm.com): #默认创建的网站文件所在目录Virtual Host Directory: /home/wwwroot/vpsmm.com===========================Allow Rewrite rule? (y/n)===========================y #是否添加伪静态文件Please enter the rewrite of programme:wordpress,discuz,typecho,sablog,dabr rewrite was exist.(Default rewrite: other):typecho #小夜用的typecho程序===========================You choose rewrite=typecho======================================================Allow access_log? (y/n)===========================n #是否启用日志文件======================================================Create database and MySQL user with same name (y/n)======================================================y #是否创建mysql数据库verify your current MySQL root password: **** #输入安装时的mysql数据库root密码Warning: Using a password on the command line interface can be insecure.MySQL root password correct.Enter database name: vpsmm_user #创建数据库用户名Your will create a database and MySQL user with same name: vpsmm_userPlease enter password for mysql user vpsmm_user: vpsmmpasswdYour password: vpsmmpasswd #创建相应密码Press any key to start create virtul host...Create Virtul Host directory......set permissions of Virtual Host directory......You select the exist rewrite rule:/usr/local/nginx/conf/typecho.confGracefully shutting down php-fpm . doneStarting php-fpm doneTest Nginx configure file......nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successfulRestart Nginx......Warning: Using a password on the command line interface can be insecure.Warning: Using a password on the command line interface can be insecure.User vpsmm_user create Sucessfully.Warning: Using a password on the command line interface can be insecure.Warning: Using a password on the command line interface can be insecure.Warning: Using a password on the command line interface can be insecure.Database: vpsmm_user create Sucessfully.Warning: Using a password on the command line interface can be insecure.Warning: Using a password on the command line interface can be insecure.GRANT ALL PRIVILEGES ON vpsmm_user Sucessfully.Warning: Using a password on the command line interface can be insecure.FLUSH PRIVILEGES Sucessfully.================================================Virtualhost infomation:Your
EasyGoServer作者:林冠宏 / 指尖下的幽灵掘金:https://juejin.im/user/587f0dfe128fe100570ce2d8博客:http://www.cnblogs.com/linguanh/GitHub : https://github.com/af913337456/联系方式 / Contact:913337456@qq.comEasyGoServer---- 概述---- 脚本介绍-------- Linux-------- Windows-------- Mac---- 使用流程---- 部分代码说明---- 开源地址概述一个能够仅仅依赖你创建好的 sql 文件,就能 自动帮你生成基础服务端框架代码 的 go server 框架。包含有:1,基础的 增删改查2,拓展性强的API3,客户端的数据传入 与 服务端的输出 全部依赖 struct例如你的一个输入结构体 inputStruct 设置为type inputStruct struct {Id int64 `json:"id" nullTag:"1"` // nullTag==1 指明 id 必须要求在客户端传入 {"id":123}Name string `json:"name" nullTag:"0"` // ==0 指明 name 在客户端输入的时候可以不必要}对应上例,客户端输入的 json : {"id":666, "name":"lgh"}当你在使用 select 的时候,你的 sql 如果是这样的:select User.id , User.age from User那么你的对应输出结构体 outputStruct 应该是:type inputStruct struct {Id int64 `json:"id"`Age int64 `json:"age"`}4,真正需要你写的代码极少,例如第三点的例子,你要写的就那么多,其中默认的 struct 会自动帮你生成脚本介绍根据 sql 文件,自动生成代码文件,包含有 struct.go,每张表对应生成一个包含有增删改查的基础方法文件one_key_create_code根据内置的 makefile 或者 .bat 编译并运行默认的 go server 程序,注意是默认的make_serverLinuxone_key_create_code.shmake_server.shMakefileWindowsone_key_create_code.batmake_server.batMac参照 linux 的使用流程1,在你的 服务器 安装 mysql 或者 mariadb2,编写好的你的 sql 文件,可以参照我源码里面的 this.sql3,运行步骤2编写好的 sql 文件4,修改 sql_2_api.go 里面 main 内的 sql 文件名称5,运行 one_key_create_code 脚本,成功后会在同级目录生成下面文件,记得刷新目录struct.go,里面包含注释规范对应你 sql 文件里面的表名称生成的函数文件,格式:func_表名称.go6,自己写好,main.go 或者 使用我提供的默认 LghSampleMain.go,在里面 添加你自己的路由router.HandleFunc("/insert",insert_luser_sample).Methods("POST")router.HandleFunc("/select",select_luser_sample).Methods("GET")router.HandleFunc("/update",update_luser_sample).Methods("POST")router.HandleFunc("/delete",delete_luser_sample).Methods("POST")7,配置好 conf.json 文件,我里面有例子// Host 是绝对路径// Port 是要被监听的端口{"Host": "127.0.0.1","Port": ":8884","FilePort":":8885","DbName":"database","DbUser":"root","DbPw":"123456","DbPort":"3306"}8,现在执行 make_server 脚本,观察控制台的输出,即可。部分代码说明核心的参数结构体type LghRequest struct {w http.ResponseWriterr *http.Request// 标记使用,当前的方法名称funcName string// 输入的结构体,与客户端输入的 json 成对应关系inputStruct interface{}// 自定义 slices 的回调,方便你做参数处理,返回 true 意味着此次操作终止,例如 updateslicesCallBack func(slices []interface{}) bool// 根据传入的 jsonObj 生成的 slices 来回调,方法生成自定义 sqlgetSqlCallBack func(slices []interface{},inputStruct interface{}) string}例子方法1,演示不需要参数的形式/** 演示不需要参数的形式 */func update_0(w http.ResponseWriter,r *http.Request) {request := LghRequest{w,r,"update_luser",nil, /** nil 表示没输入结构体 */func(slices *[]interface{}) bool{return false},func(slices *[]interface{},inputStruct interface{}) string {return "update LUser set u_user_id='444' where id='1'"}}updateDataByStruct(request)}2,演示当有参数输入的时候,参数仅做判断,但是不需要组合到 sql 的情况/** 演示当有参数输入的时候,参数仅做判断,但是不需要组合到 sql的情况 */func update_1(w http.ResponseWriter,r *http.Request) {type testS struct {Id int64 `json:"id" nullTag:"1"` // nullTag==1 指明 id 必须要求在客户端传入 {"id":123}}request := LghRequest{w,r,"update_luser",new (testS),func(slices []interface{}) bool{// 在这里对 slices 做你想做的操作,增加或者删除等等if slices[0] == -1{return true /** 返回 true,终止插入,提示错误或者其它 */}slices = append(slices[:0], nil) /** 自己做完处理删除掉 */return false},func(slices []interface{},inputStruct interface{}) string {// 如果你想根据输入的 json 数据来特定生成 sql,那么就可以在这里使用 slices 来操作return "update LUser set u_user_id='444' where id='2'"}}updateDataByStruct(request)}3,演示使用输入参数的情况/** 演示使用输入参数的情况 */func update_luser_sample(w http.ResponseWriter,r *http.Request) {type testS struct {Id int64 `json:"id" nullTag:"1"`}request := LghRequest{w,r,"update_luser",new (testS),func(slices []interface{}) bool{return false},func(slices []interface{},inputStruct interface{}) string {return "update LUser set u_user_id='444' where id=?" /** 对应 id */}}updateDataByStruct(request)}开源地址https://github.com/af913337456/EasyGoServer
一、移除mariadb 由于CentOS默认安装了mariadb,所以在安装MySql之前先移除mariadb,使用命令:yum remove mariadb-libs.x86_64,如下图所示: 二
这篇文章主要介绍了MariaDB中的thread pool详细介绍和使用方法,thread pool对高并发的环境是很好的一个解决方法,需要的朋友可以参考下
这篇文章主要介绍了今日在安装MariaDB的时候始终提示如下错误,但是我已经安装了libaio-devel库,需要的朋友可以参考下
这篇文章主要介绍了MySQL分支选择参考:Percona还是MariaDB,本文分别讲解了Percona、MariaDB背景知识,对使用它们的选择给出了参考,需要的朋友可以参考下
本文给大家介绍Mysql/MariaDB启动时一直处于进度条状态,进度条结束后提示error。究竟是什么原因呢?该怎么解决呢?跟着小编一起看看该如何解决此问题呢。
MariaDB是MySQL源代码的一个分支,在意识到Oracle会对MySQL许可做什么后分离了出来(MySQL先后被Sun、Oracle收购)。除了作为一个Mysql的“向下替代品”,MariaDB包括的一些新特性使它优于MySQL。通过本篇文章给大家介绍MySQL和mariadb区别,需要的朋友可以参考下