Sunday, January 29, 2017

Using SQL to build a simple test database

I need a database for my newest python app.

So to test my app, I need to create a test database, and fill it with test data.

As a start, here's the SQL to create a client table, with one field (for now), and insert 3 records into it:

use tempdb;
drop table clients;
create table clients
(
client_name varchar(80)
);
insert into clients values ('client1');
insert into clients values ('client2');
insert into clients values ('client3');

Saturday, January 28, 2017

Logging in to MySQL from a python script

When I try and run my tests, I get this error:

[ed@mikado STC.Sendgrid.Collector]$ bash build.sh
ERROR 1044 (42000) at line 1: Access denied for user ''@'localhost' to database 'tempdb'


I can log in to mySQL on the command line like this:

 sudo mysql --user=root --password=xxxxx tempdb
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.1.20-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

This is well-described here.

I want to see what tables are available:

MariaDB [tempdb]> show tables;
show tables;
Empty set (0.00 sec)

No tables, but still, the python script should let me log on.

OK, turns out that my user name and password need to be set as environment vars.

When I try this I get further:

PYTHONPATH=. SG_DB_USER=root SG_DB_PASSWORD=xxxx pytest