mysql

Why does TRANSACTION / COMMIT improve performance so much with PHP/MySQL (InnoDB)?

不问归期 提交于 2021-02-05 17:55:34
问题 I've been working with importing large CSV files of data; usually less than 100,000 records. I'm working with PHP and MySQL (InnoDB tables). I needed to use PHP to transform some fields and do some text processing prior to the MySQL INSERT s (part of process_note_data() in code below). MySQL's LOAD DATA was not feasible, so please do not suggest it. I recently tried to improve the speed of this process by using MySQL transactions using START TRANSACTION and COMMIT . The performance increase

Web全栈~29.MySQL

左心房为你撑大大i 提交于 2021-02-05 15:25:07
Web全栈~29.MySQL 上一期 MySQL安装 根据自己的需求选择~ 不过本人选了第一个,开发者默认~ 大多数操作,只需要默认下一步就好了,就不一一发截图了~ 接下来又是一顿next和finish~ 然后还是一顿Next和Finish~最后安装成功… 来任务管理器里面的服务看看? 默认路径C:\Program Files\MySQL\MySQL Server 8.0 配置path环境变量 计算机,右键,属性,高级系统设置,环境变量 把C:\Program Files\MySQL\MySQL Server 8.0\bin这个路径加到环境变量里面去(放最上面) 现在就可以用CMD登录MySql了 登录命令: mysql -hlocalhost -uroot -p 然后我们发现navicat无法连接MySql? 别着急,我们还有操作~ 这种错误的原因是在MySQL8之前版本中加密规则mysql_native_password,而在MySQL8以后的加密规则为caching_sha2_password。要么更新navicat驱动来解决此问题,要么就是将mysql用户登录的加密规则修改为mysql_native_password。我的话呢,就用第二种吧~ 加上这两行命令就可以了~ 设置密码永不过期 alter user 'root'@'localhost' identified by

MySQL 内核深度优化

余生长醉 提交于 2021-02-05 15:20:29
MYSQL数据库适用场景广泛,相较于Oracle、DB2性价比更高,Web网站、日志系统、数据仓库等场景都有MYSQL用武之地,但是也存在对于事务性支持不太好(MySQL 5.5版本开始默认引擎才是InnoDB事务型)、存在多个分支、读写效率瓶颈等问题。 一.内核性能的优化 由于腾讯云上的DB基本都需要跨园区灾备的特性,因此CDB for MySQL的优化主要针对主从DB部署在跨园区网络拓扑的前提下,重点去解决真实部署环境下的性能难题。经过分析和调研,我们将优化的思路归纳为:“消除冗余I/O、缩短I/O路径和避免大锁竞争”。以下是内核性能的部分案例: 1.主备DB间的复制优化 问题分析 如上图所示,在原生MySQL的复制架构中,Master侧通过Dump线程不断发送Binlog事件给Slave的I/O线程,Slave的I/O线程在接受到Binlog事件后,有两个主要的动作: 写入到Relay Log中,这个过程会和Slave SQL线程争抢保护Relay Log的锁。 更新复制元数据(包含Master的位置等信息)。 优化方法 经过分析,我们的优化策略是: 优化效果 如上图所示,经过优化:左图35.79%的锁竞争(futex)已经被完全消除;同压测压力下,56.15%的文件I/O开销被优化到19.16%,Slave I/O线程被优化为预期的I/O密集型线程。 2

MySQL模式设置方式介绍(严格模式:STRICT_TRANS_TABLES,无引擎提交:NO_ENGINE_SUBSTITUTION,填补字符长度:PAD_CHAR_TO_FULL_LENGTH)

落花浮王杯 提交于 2021-02-05 14:45:33
引入 我们之前所学的表数据类型中定义 char 或者 varchar 字段, 当你写入长度超过了你指定的长度, 他也不会报错, 这对于 mysql 来说是没有任何意义的 本篇文章主要介绍 : STRICT_TRANS_TABLES : 严格模式 NO_ENGINE_SUBSTITUTION : 无引擎提交 PAD_CHAR_TO_FULL_LENGTH : 填补字符到全长度 ps : char不指定宽度. 默认宽度是1, null 关键字没有宽度限制 一.严格模式与非严格模式 简单来说就是 MySQL 自身对数据进行严格的校验(格式、长度、类型等),比如一个整型字段我们写入一个字符串类型的数据,在非严格模式下 MySQL 不会报错, 定义的类型长度超出了也不会报错, 严格模式则会 二.不同版本的不同效果 5.6版本 默认没有开启严格模式 规定只能存一个字符你给了多个字符, 那么会自动帮你截取 5.7版本 及以上或者开启了严格模式 那么规定只能存几个 就不能超, 一旦超出范围立刻报错(Data too long for column ‘name’ at row 1) 三.严格模式的好处 使用数据库的准则 : 能尽量少的让数据库干活就尽量少, 不要给数据库增加额外的压力 而在非严格模式下, 当遇到宽度超出时, 会进行额外的截取操作这种操作就会给数据库增加额外的压力 换个角度来说,

Flask SQLAlchemy filter by value OR another

妖精的绣舞 提交于 2021-02-05 13:57:03
问题 I have a Flask project that interacts with MySQL db through Flask-SQLAlchemy . My question is, how to select a row from the database based on a value OR another value. The results I want in SQL looks like this SELECT id FROM users WHERE email=email OR name=name; How to achieve that in Flask-SQLAlchemy ? 回答1: The following may help: # app.py from flask import Flask from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'url_or_path/to/database' db

Flask SQLAlchemy filter by value OR another

天大地大妈咪最大 提交于 2021-02-05 13:55:13
问题 I have a Flask project that interacts with MySQL db through Flask-SQLAlchemy . My question is, how to select a row from the database based on a value OR another value. The results I want in SQL looks like this SELECT id FROM users WHERE email=email OR name=name; How to achieve that in Flask-SQLAlchemy ? 回答1: The following may help: # app.py from flask import Flask from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'url_or_path/to/database' db

How to execute MySQL command from the host to container running MySQL server?

﹥>﹥吖頭↗ 提交于 2021-02-05 12:46:15
问题 I have followed the instruction in https://registry.hub.docker.com/_/mysql/ to pull an image and running a container in which it runs a MySQL server. The container is running in the background and I would like to run some commands. Which is the best way to connect to the container and execute this command from command line? Thanks. 回答1: You can connect to your mysql container and run your commands using: docker exec -it mysql bash -l (Where mysql is the name you gave the container) Keep in

Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement [duplicate]

拥有回忆 提交于 2021-02-05 12:36:36
问题 This question already has answers here : When to use single quotes, double quotes, and backticks in MySQL (13 answers) Closed 5 years ago . I receive the following error: Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement I am having trouble binding and executing the prepare statement. The connection to the database is succesfully established and it does manage to insert it into the database with the initial value of ? Below is the

Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement [duplicate]

喜欢而已 提交于 2021-02-05 12:35:02
问题 This question already has answers here : When to use single quotes, double quotes, and backticks in MySQL (13 answers) Closed 5 years ago . I receive the following error: Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement I am having trouble binding and executing the prepare statement. The connection to the database is succesfully established and it does manage to insert it into the database with the initial value of ? Below is the

mysql syntax error in query [closed]

让人想犯罪 __ 提交于 2021-02-05 12:29:07
问题 Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Improve this question I'm getting an error Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '5,7,6,9,13 ORDER BY n.date DESC' at line 5. Can anyone point out what's wrong? Thanks $news