четверг, 27 июля 2017 г.

Восстановление MySQL репликации

Источник

# Остановить работу slave
mysql> stop slave;
# заставить slave забыть позицию его репликации в файле лога master'а
mysql> reset slave;
# Заставить slave читать начиная с той позиции на которой остановился
mysql> change master to master_log_file='mysql-bin.000048', master_log_pos=283932126;
# Запустить slave
mysql> start slave;

How To resolve “Database Mail is stopped” error

Source

You try to send Test mail from Database mail but it throws below message-
Msg 14641, Sev 16, State 1, Line 81 : Mail not queued. Database Mail is stopped. Use sysmail_start_sp to start Database Mail. [SQLSTATE 42000]
1. To investigate this issue, firstly confirm whether Database Mail is enabled or not by executing below queries in SQL Server Management Studio-
       sp_configure 'show advanced', 1; 
       GO
       RECONFIGURE;
       GO
       sp_configure;
       GO
If the resultset show run_value as 1 then Database Mail is enabled.
2. If the Database Mail option is disabled then run the below queries to enable it-
       sp_configure 'Database Mail XPs', 1; 
       GO
       RECONFIGURE;
       GO
       sp_configure 'show advanced', 0; 
       GO
       RECONFIGURE;
       GO
3. Once the Database Mail is enabled then start it using below query on msdb database-
       USE msdb ;       
       EXEC msdb.dbo.sysmail_start_sp;
4. To confirm that Database Mail External Program is started, run the below query-
       EXEC msdb.dbo.sysmail_help_status_sp;
5. If the Database Mail external program is started then check the status of mail queue using below statement-
       EXEC msdb.dbo.sysmail_help_queue_sp @queue_type = 'mail';

For more details please check the link http://technet.microsoft.com/en-us/library/ms187540.aspx

пятница, 14 июля 2017 г.

Create a read only account

Script to Create Read-Only user:
CREATE ROLE Read_Only_User WITH LOGIN PASSWORD 'Test1234' 
NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION VALID UNTIL 'infinity';
Assign permission to this read only user:
GRANT CONNECT ON DATABASE YourDatabaseName TO Read_Only_User;
GRANT USAGE ON SCHEMA public TO Read_Only_User;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO Read_Only_User;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO Read_Only_User;

четверг, 13 июля 2017 г.

Create super user and database user in Mongo 2.6

source

# Create your superuser
$ mongo
> use admin
> db.createUser({user:"someadmin",pwd:"secret", roles:[{role:"root",db:"admin"}]})
> exit
# Alias for convenience (optional and at your own risk)
$ echo 'alias mongo="mongo --port 27017 -u someadmin -p secret --authenticationDatabase admin"' >> ~/.bash_profile
$ source ~/.bash_profile
# Add user to your DB
$ mongo
> use some_db
> db.createUser(
{
user: "mongouser",
pwd: "someothersecret",
roles: ["readWrite"]
}
)
# If you get locked out, start over
sudo service mongod stop
sudo mv /data/admin.* . # for backup
sudo service mongod start