Categories
Mariadb

mariadb user and permissions

grant privileges. here are some good commands to remember:

create user `airports`@`localhost` identified by 'my-password'
grant usage on airports.* to `airports`@`localhost`;
grant all privileges on `airports`.* to `airports`@`localhost`;
select user,host from mysql.user where user like 'airports';
+----------+-----------+
| User     | Host      |
+----------+-----------+
| airports | %         |
| airports | localhost |
+----------+-----------+
flush privileges;
debugging:
select user()
select current_user()

Categories
golang Mariadb

Go mysql config

I found that when using mysql.Config, I need to add AllowNativePasswords: true for a connection to mariadb from my go program

 30 cfg := mysql.Config{
 31         User: os.Getenv("DBUSER"),
 32         Passwd: os.Getenv("DBPASS"),
 33         Net: "tcp",
 34         Addr: "172.18.0.6:3306",
 35         AllowNativePasswords: true,
 36         DBName: "recordings",
 37     }
 ...
 42 db, err = sql.Open("mysql",cfg.FormatDSN())

Categories
java Mariadb

Java Mysql

Oh my… switched to java spring a while ago and finally started to log my notes. lots of jpa/hibernation to come..

In the database, the date column can be null. jpa doesnt like this.
one shop says that 2 different ways to get rid of the issue:
1.

UPDATE table SET datefield = NULL WHERE datefield = '0000-00-00 00:00:00';

I like it.
2.

jdbc:mysql://localhost:3306/yourMySqlDatabase?zeroDateTimeBehavior=convertToNull

I like it also.
I guess it is a preference thing. both methods are easy enough to implement. database defaults to null value …

Categories
Docker Mariadb

mysqlimport

When importing a data file into mysql/mariadb, I found that the below line works:


 docker exec -it some-mariadb mysqlimport -u root -pmy-secret-pw --local --ignore-lines 1 --columns month,day,time,username,ip,port,notes hacktrack  ./data/raw/ssh_failure.tab.txt
Categories
Docker Mariadb

docker mysql load dump file

This is how to load a sql dump file from directory to a mysql database in a container.

Make sure you have a volume set up with the directory you keep your sql files in.  In my case, I have a directory called “/data/raw” that I keep all my csv and sql files in for loading and dumping.

docker command

sudo docker run --name some-mariadb -v /data/mysql:/var/lib/mysql -v/data/raw:/data/raw-e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:latest

or…

docker-compose yaml file.


  mariadb:
    image: mariadb
    container_name: some-mariadb
    environment:
    - "MYSQL_ROOT_PASSWORD:my-secret-pw"
    volumes:
    -  /data/mysql:/var/lib/mysql
    - /data/raw:/data/raw
    ports:
    - 3306:3306

I change the directory to my /data/raw directory on my linux box that I’m running the container on.

To load a file into mysql/mariadb, open mysql from the command line:


docker exec -it  some-mariadb mysql -u root -pmy-secret-pw my-database

 

and then…


MariaDB []> source /data/raw/dump-file_data.sql

 

I use the same method for postgres

Categories
Mariadb Uncategorized

mysql add user

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql

Categories
Mariadb

Mariadb

Reminder: backup your database!

mysqldump -u username -p database_name > database_name.20190118.sql
sudo docker run --name some-mariadb -v /data/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:latest