Posts about Databases
mysql update with random values from list
“UPDATE book set year = ELT(1+FLOOR(RAND()*3), 2012,2013,2014)”
postgres-terminate-connection
MySQL
MySQL tips:
Create database with charset utf8
Grant everything to local user on all tables
Grant everything to remote user on all tables
GRANT ALL PRIVILEGES ON db_name.* TO my_user@'IP_of_host_user_connects_from' IDENTIFIED BY 'my_secret_password';
If you want to add only SELECT or something else instead of ALL there are other available privileges like:
SELECT, UPDATE, ALTER, CREATE, DELETE, DROP, SHOW DATABASES CREATE TEMPORARY TABLES, EXECUTE, FILE, GRANT OPTION, INDEX, INSERT, LOCK TABLES, PROCESS, REFERENCES, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, SHUTDOWN, SUPER, USAGE
After all you want to reload privileges because when mysqld starts, it reads all grant table contents into memory. The in-memory tables become effective for access control at that point. To tell the server to reload the grant tables, perform a flush-privileges operation.
Execute sql :
or you can even do it from shell by
or
postgres
Quick tip:
I started with MySQL db (not speaking of Delphi ADO or something like this ) Now because of my job I had to switch to Postgres and I thought "ok but it's SQL so it will be the same" - not really I had a lot of problems like in the beginning like user privileges owners of databases and tables, showing tables , showing databases So if youre switchng from mysql it can help you for beginning:
So first problem was my user access - I couldnt access postgres even through root :) so after clean installation if you want to launch psql client for postgres just su as postgres after that you can create your own super user or user having privileges to specific database
and then you should be able to do everything
To see databases "show databases;" didn't work anymore :) in postgres
connect to database:
show tables; in database:
Explain or describe table:
Show all shortcuts:
Backup
To dump database to sql script with inserts etc use pg_dump remember (it wont dump user privileges):
The better way of dumping database is pg_dumpall it dumps database users and groups, tablespaces, access permissions that apply to databases as a whole.
If you want to move your users of postgres to different server you can:
Restore
TO simply restore backup pgdump sql file :
Access Privileges:
Another way is about accessing postgresql if you worked with mysql you could just provide : grant all privileges on db to user_name@localhost or user_name@'10.0.0.1' here it's not the same. Privileges can be configured in low level pg_hba.conf file where you provide who(sys user) who(db_user) where_from . Adding user in postgres:
Create user:
change owner of db:
change owner of tables:
rename db