mysql

Safe way to store mysql server credentials in flask?

夙愿已清 提交于 2021-02-07 19:55:22
问题 I was wondering about the safety of some thing in my app.py flask app. First the database, I'm using mysql and currently I am connecting to it in the following way: # Config MySQL app.config['MYSQL_HOST'] = 'localhost' app.config['MYSQL_USER'] = 'root' app.config['MYSQL_PASSWORD'] = 'password' app.config['MYSQL_DB'] = 'databasename' app.config['MYSQL_CURSORCLASS'] = 'DictCursor' And to me this feels very weird, just putting in your password in plain text etc. I've been searching online but

Converting MySQL results into comma separated values

送分小仙女□ 提交于 2021-02-07 19:54:55
问题 I have a mysql statement that will produce a bunch of results. I want to split each result with a comma except the last result. I was thinking that I would need a for loop but I am not quite sure how to go about it. Should I get my results as an array and loop through them? I was thinking that I should count the rows and then when the for reaches the last result it doesn't use a comma. I am so used to just getting the results with while that I am a bit of a noob using for. I would appreciate

Spring transaction and rollback on multiple tables

走远了吗. 提交于 2021-02-07 19:50:39
问题 I'm struggling on transaction magement using DAO. The scenario is to create new quote that contains a list of quote_line and a customer. If the customer doesn't exist, it will insert it in the table customer. My code is architectures as follow : @Entity @Table(name = "quote") public class Quote { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; //....properties @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "customer_id", nullable = true) private Customer customer;

How can I get the offset of a particular row in MySQL?

Deadly 提交于 2021-02-07 19:39:22
问题 I'm trying to make an image database which does not keep a consistent record of ID's. For example it might go 1,2,6,7,12, but as you can see that is only 5 rows. Inside the table I have fileid and filename. I created a PHP script to show me the image when I give the fileid. But if I give it the ID 5 which does not exist I get an error. That's fine as I want an error for that, but not for users who will browse through these images using forward and back buttons. The forward and back buttons

Databases: Migrate data between MS Access DB and MYSQL

梦想的初衷 提交于 2021-02-07 19:33:48
问题 I have 2 databases, one is MS Access DB from an old website, and the other one is MYSQL from the new Joomla+VirtueMart based website. I need to migrate existing products from MS Access to MYSQL. I thought of putting both on server and writing SQL queries in MYSQL workbench, untill I have a good script for that, but I'm very new to SQL, so I'd rather avoid that. I there a better way and more efficient for that? 回答1: You can always export to CSV and import that in MySQL. 回答2: you can use tools

How to use avg function?

柔情痞子 提交于 2021-02-07 18:42:38
问题 I'm new at php and mysql stuff and i'm trying to use an avg function but i don't know how to. I'm trying to do something like this: mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die ("Did not connect to $database"); mysql_query("AVG(column1) FROM table1 ") or die(mysql_error()); mysql_close(); echo AVG(column1); (Q1)I'd like to see the value printed in the screen, but i'm getting nothing but an error message. How could I print this average on the screen ? (Q2)If

【数据库相关】mysql-select count (*) 总结

喜你入骨 提交于 2021-02-07 18:36:02
今天看到个帖子,select count (*) from table 这个语句有很多的说道儿,想了一下就一条普普通通,简单的不能再简单的查询语句能有什么说道儿? 继续往下看了帖子,发现这玩意真的是有点东西。 1.验证: 首先这个语句是平时查询数量的时候常用的语句,当数据量足够大的时候,这个语句就显现出来问题了。 故上项目中的数据库中找一个最大的表来进行验证。发现这个表用正常的建表,建主键的时候。执行这条语句所需的时间很长,长到我已经没有耐心等到他查询出来结果了。 2.分析 这条语句为什么会执行这么长时间? 当然这条语句肯定不能在进行优化了(本人没有再进行优化的能力了),那为什么这个语句会执行这么长时间?看了帖子发现,是因为这个表的表结构中只有一条聚簇索引(本人理解:创建表的时候,主键自动生成的索引就叫聚簇索引),而执行这条语句的时候,在InnoDB存储引擎中,count(*)函数是先从磁盘中读取表中的数据到内存缓冲区,然后扫描全表获得行记录数的。因此查询的时间固然长。 3.优化 那么这种情况该如何优化呢? 就要用到一个二级索引的概念了,二级索引也叫辅助索引,也就是除了聚簇索引以外的索引都叫辅助索引。辅助索引的每一行记录都包含每一行的主键列,索引指向主键,InnoDB使用这个主键查找聚簇索引中的行。 那么在表中加上二级索引后执行的效率如何呢? 效率是瞎眼可见的提升。 4.结论

FUNCTION database.AddDays does not exist

夙愿已清 提交于 2021-02-07 18:17:26
问题 I'm trying to use dbfunction from EF6 on database MySQL but I get the follow exception "FUNCTION database.DiffDays does not exist". I used this code: var aux = bd.Atos.Where(w => w.IdAtivo == 1 && w.IdUtilizador == idUtilizador && DbFunctions.DiffDays(DbFunctions.AddDays(w.Data, w.NumDias).Value, DateTime.Now).Value < numeroDias) What I'm missing? 来源: https://stackoverflow.com/questions/24442260/function-database-adddays-does-not-exist

FUNCTION database.AddDays does not exist

独自空忆成欢 提交于 2021-02-07 18:16:41
问题 I'm trying to use dbfunction from EF6 on database MySQL but I get the follow exception "FUNCTION database.DiffDays does not exist". I used this code: var aux = bd.Atos.Where(w => w.IdAtivo == 1 && w.IdUtilizador == idUtilizador && DbFunctions.DiffDays(DbFunctions.AddDays(w.Data, w.NumDias).Value, DateTime.Now).Value < numeroDias) What I'm missing? 来源: https://stackoverflow.com/questions/24442260/function-database-adddays-does-not-exist

Reset root password in MySQL 8

ぃ、小莉子 提交于 2021-02-07 18:02:05
问题 When I use the method to reset the root password described on How to Reset the Root Password, starting the server with mysqld --init-file=/home/username/init-file doesn't work. It gives the following error. [Server] Could not open /var/log/mysqld.log file for error logging: Permission denied. Permissions are correct. Server starts when I use service mysqld start . I am using MySQL 8.0.12 on Fedora 28. 回答1: If you can log in to your MySQL server and you want to change your password by query