Showing posts with label Database Server. Show all posts
Showing posts with label Database Server. Show all posts

Sunday, 28 October 2018

Mariadb secure configuration on CentOS 7


For secure your MariaDB by setting up the following,
1. Set up root password
2. Disabling remote root login
3. Removing test database 
4. Removing anonymous users
Finally reload the privileges.



[root@server ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ...
Success!
 
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

 
[root@server ~]#

[root@server ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 657
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 


MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]>


 

Sunday, 10 June 2018

Session Expired, Please login again when using Adminer


I was trying to access the database using adminer.php but I could not able to login, even though I filled in the correct credentials.




The log file gave me the exact issue.

[root@beta-server ]# cat /var/log/nginx/error.log

[error] 24318#24318: *46 FastCGI sent in stderr: "PHP message: PHP Warning:  Unknown: open(/var/lib/php/session/sess_0c6qn562knk0fm7vkil358kr80, O_RDWR) failed: Permission denied (13) in Unknown on line 0
PHP message: PHP Warning:  Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0" while reading upstream, client: 10.130.12.45, server: example.com, request: "GET /?username=root HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-fpm.sock:", host: "example.com", referrer: "http://example.com/?username=root"




Solution



These errors occur because PHP has no way of saving sessions on disk.

The location of the PHP session path can be found in "/etc/php.ini" under session.save_path. The default path is /var/lib/php/session. If this directory does not exist, then create it and change permissions on it.

[root@beta-server ]# chmod -R 700 /var/lib/php/session
[root@beta-server ]# chown nginx.nginx -R /var/lib/php/session

After all these changes, i can able to login successfully.


Thursday, 12 October 2017

Mysql Command line cheat sheet

List of mysql commands


Connecting Mysql : mysql -u username -p  ( will prompt for password )

Show all databases : show databases;

Create a new database : create database database_name;

Select database: use database_name;

Show all tables : show tables;

Show table structure : describe table_name;

MySQL open database connections : show status like '%onn%';

 MySQL show processlist : show processlist;

Deleting tables : drop table table_name;

Deleting databases: drop database database_name;

Export a database dump : mysqldump -u username -p database_name > database_dump.sql

Import a database dump : mysql -u username -p database_name < database_dump.sql

Create a new user: create user 'username'@'localhost' identified by 'password'

List out the users : select user,password,host from mysql.user