Wonderjar's Blog

各种数据库docker初始化,其他命令记录

2018-09-17

Mongo

docker run -p 28918:27017 -d –name some-mongo -e MONGO_INITDB_ROOT_USERNAME=root -e MONGO_INITDB_ROOT_PASSWORD=root mongo

MySql

mysql -h HOST -u USERNAME -p
show databases;
use DBNAME;
show tables;

mysqldump -u username -p dbname > dbexport.sql

mysql -u username -p dbname < dbexport.sql

docker run –name some-mysql -e MYSQL_ROOT_PASSWORD=root -d mysql

show processlist;
select from information_schema.innodb_locks;
select
from information_schema.innodb_trx \G;

PostgreSQL

docker run –name some-postgres -e POSTGRES_USER=exampleuser -e POSTGRES_PASSWORD=exampleuser -d postgres

如果不用docker安装,

sudo su postgres psql

认证失败,

sudo find / -type f -name pg_hba.conf 2> /dev/null

Add a new line to the top of pg_hba.conf:

1
local    postgres     postgres     peer

/Library/PostgreSQL/9.6/pg_ctl -D /Library/PostgreSQL/9.6/data stop

/Library/PostgreSQL/9.6/pg_ctl -D /Library/PostgreSQL/9.6/data start

查看DB
\l
选择DB
\c DB1

createdb -E utf8 -T template0 –lc-collate=en_US.UTF-8 –lc-ctype=en_US.UTF-8 exampledb
CREATE USER exampleuser WITH PASSWORD ‘examplepassword’;
ALTER DATABASE exampledb OWNER TO exampleuser;
ALTER SCHEMA public OWNER TO exampleuser;

查看当前 -D

ps aux | grep postgres | grep – -D

查看当前连接

SELECT * FROM pg_stat_activity;

重启
pg_ctl reload -D /var/lib/postgresql/9.4/main -c config_file=/etc/postgresql/9.4/main/postgresql.conf

pg_dump TestDb1>TestDb14.sql