mysql

How to create a mysqldump client based on docker to export the contents of a specific database

旧城冷巷雨未停 提交于 2021-02-10 16:43:45
How to create a mysqldump client based on docker to export the contents of a specific database Dumping the database structure for all table with no data docker run -it --rm \ mysql:5.7.28 \ mysqldump \ --host=192.168.1.131 \ --port=3306 \ --no-data \ --databases nacos \ --user=root \ --password=Gah6kuP7ohfio4 > nacos.sql Dumping the database structure for all table with with data docker run -it --rm \ mysql:5.7.28 \ mysqldump \ --host=192.168.1.131 \ --port=3306 \ --databases nacos \ --user=root \ --password=Gah6kuP7ohfio4 > nacos.sql 来源: oschina 链接: https://my.oschina.net/qwfys200/blog

【MySQL】-2 函数、分组、子查询、联合查询

前提是你 提交于 2021-02-10 16:37:25
函数   Mysql的函数特性没有SQL可移植性强。   大多数情况下支持的函数:   处理文本串的函数:     RTrim():处理列值右边的空格    LTrim():处理列值左边的空格    Trim():处理列值的左右两边的空格(中间的不处理)    Upper():文本转大写    Length():返回串的长度    Locate():找出串的一个子串    Lower():文本转小写    ...   算术操作函数:     包含一些常见的数值处理函数如:     Abs()取绝对值;     Mod()返回除操作的余数;     Pi()返回圆周率;     Rand();返回一个随机数;     Exp()返回一个数的指数值;   处理日期和时间的函数:     列举常用的几个:     CurDate() 返回当前日期;     CurTime()返回当前时间;     Date()返回日期时间的日期部分     Date_Format()返回一个格式化的日期或时间     Time()返回一个日期时间的时间部分     ...   查询订单表中,发生于2005-09-01日的订单的有关信息: select cust_id, order_num from orders where date(order_date) = ' 2005-09-01 ' ;  

还在为生成分布式ID发愁?UUID、数据库、算法、Redis、Leaf 来帮忙

随声附和 提交于 2021-02-10 16:35:25
前言 一般单机或者单数据库的项目可能规模比较小,适应的场景也比较有限,平台的访问量和业务量都较小,业务ID的生成方式比较原始但是够用,它并没有给这样的系统带来问题和瓶颈,所以这种情况下我们并没有对此给予太多的关注。但是对于大厂的那种大规模复杂业务、分布式高并发的应用场景,显然这种ID的生成方式不会像小项目一样仅仅依靠简单的数据自增序列来完成,而且在分布式环境下这种方式已经无法满足业务的需求,不仅无法完成业务能力,业务ID生成的速度或者重复问题可能给系统带来严重的故障。所以这一次,我们看看大厂都是怎么分析和解决这种ID生成问题的,同时,我也将我之前使用过的方式拿出来对比,看看有什么问题,从中能够得到什么启发。 分布式ID的生成特性 在分析之前,我们先明确一下业务ID的生成特性,在此特性的基础上,我们能够对下面的这几种生成方式有更加深刻的认识和感悟。 全局唯一 ,这是基本要求,不能出现重复。 数字类型,趋势递增 ,后面的ID必须比前面的大,这是从MySQL存储引擎来考虑的,需要保证写入数据的性能。 长度短 ,能够提高查询效率,这也是从MySQL数据库规范出发的,尤其是ID作为主键时。 信息安全 ,如果ID连续生成,势必会泄露业务信息,甚至可能被猜出,所以需要无规则不规则。 高可用低延时 ,ID生成快,能够扛住高并发,延时足够低不至于成为业务瓶颈。 分布式ID的几种生成办法

MySQL 加锁和死锁解析

让人想犯罪 __ 提交于 2021-02-10 16:32:36
##产生死锁的必要条件 多个并发事务(2个或者以上) 每个事物都持有了锁(或者是已经在等待锁) 每个事务都需要再继续持有锁(为了完成事务逻辑,还必须更新更多的行) 事物之间产生加锁的循环等待,形成死锁 常规锁模式 LOCK_S(读锁,共享锁) LOCK_X(写锁,排它锁) 锁的属性 LOCK _REC_NOT_GAP(锁记录) LOCK_GAP(锁记录前的GAP) LOCK_ORDINARY(同时锁记录+记录前的GAP,Next key锁) LOCK_INSERT_INTETION(插入意向锁) 锁组合(属性+模式) 可以任意组合 锁冲突矩阵 锁是加在那里的? 根据主键查找-锁加在主键上 如 begin;select * from tt_copy where id=4 for update; 加锁情况 index PRIMARY of table test . tt_copy trx id 1101588 lock_mode X locks rec but not gap 根据普通索引查找-锁加在普通索引和主键上 如 begin;select * from tt_copy force index(idx_a) where a=4 for update; 加锁情况 index idx_a of table test . tt_copy trx id 1101590 lock_mode

Stored procedure works on MySQL workbench, but not in python

点点圈 提交于 2021-02-10 16:21:52
问题 I'm testing a database where i have 3 tables, number 1 is storing user information, number 2 is storing the latitude and longitude for different cities, and there's a 3rd table storing the location of a user and it's distance to the closest city. The 3rd table has a composite key from primary keys of the other two tables. I have written a stored procedure in mysql workbench that takes in 5 variables then it inserts data into the 3rd table, here's the code using some random variables: SET

Stored procedure works on MySQL workbench, but not in python

给你一囗甜甜゛ 提交于 2021-02-10 16:21:19
问题 I'm testing a database where i have 3 tables, number 1 is storing user information, number 2 is storing the latitude and longitude for different cities, and there's a 3rd table storing the location of a user and it's distance to the closest city. The 3rd table has a composite key from primary keys of the other two tables. I have written a stored procedure in mysql workbench that takes in 5 variables then it inserts data into the 3rd table, here's the code using some random variables: SET

How do I remove results based on conditions to calculate an average and specific movie

不想你离开。 提交于 2021-02-10 16:20:51
问题 I have the schema below. A quick explanation of it is: bob rated the movie up, 5/5 james rated the movie up, 1/5 macy rated the movie up, 5/5 No one has rated the movie avengers. The logic: If I am personA, look up everyone I have blocked. Look up all the movie reviews. Anyone who has left a movie review, and personA has blocked, remove them from the calculation. Calculate the average rating of the movies. CREATE TABLE movies ( id integer AUTO_INCREMENT primary key, name varchar(100) NOT NULL

Uncaught Error: Call to a member function prepare() on null error [duplicate]

荒凉一梦 提交于 2021-02-10 16:11:58
问题 This question already has an answer here : Fatal error Call to a member function prepare() on null (1 answer) Closed 3 years ago . I know there were a lot of answers related to this error, but I still don't know how to solve it... I'm trying to make the database connection, which would connect to the database and insert user's entered values in it and i got this error. I've created 2 files (with different classes): Here is a connection file: <?php class Connection { // Setting Database Source

Uncaught Error: Call to a member function prepare() on null error [duplicate]

天大地大妈咪最大 提交于 2021-02-10 16:10:31
问题 This question already has an answer here : Fatal error Call to a member function prepare() on null (1 answer) Closed 3 years ago . I know there were a lot of answers related to this error, but I still don't know how to solve it... I'm trying to make the database connection, which would connect to the database and insert user's entered values in it and i got this error. I've created 2 files (with different classes): Here is a connection file: <?php class Connection { // Setting Database Source

Connecting to Aurora MySQL Serverless with Node

爷,独闯天下 提交于 2021-02-10 15:54:00
问题 I'm trying to connect to my Aurora Serverless MySQL DB cluster using the mysql module, but my connection always times out. const mysql = require('mysql'); //create connection const db = mysql.createConnection({ host : 'database endpoint', user : 'root', password : 'pass', database : 'testdb' }); //connect db.connect((err) => { if(err){ throw err; console.log('connection failed'); } console.log('mysql connected...'); }) db.end(); My cluster doesn't have a public IP address so I'm trying to use