Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

CentOS Selinux

Install setroubleshoot.noarch to show selinux error messages:
 yum install setroubleshoot-server.noarch setroubleshoot.noarch


Allow Apache to listen to a different port and check which port is selinux allowed:

semanage port -a -t http_port_t -p tcp 81

semanage port -l


selinux also prevent mysqld to start after relocate /var/lib/mysql to /home/mysql:
 chcon -R -t mysqld_var_run_t /home/mysql 
ll -Z .
-rw-rw---- mysql mysql user_u:object_r:mysqld_var_run_t ibdata1
-rw-rw---- mysql mysql user_u:object_r:mysqld_var_run_t ib_logfile0
-rw-rw---- mysql mysql user_u:object_r:mysqld_var_run_t ib_logfile1
drwx------ mysql mysql user_u:object_r:mysqld_var_run_t mysql
drwx------ mysql mysql user_u:object_r:mysqld_var_run_t test

Allow mysqld to use /home/mysql

# cat /tmp/avc
host=tortoise type=AVC msg=audit(1221459330.317:413): avc: denied { create } for pid=7642 comm="mysqld" name="forum_db" scontext=system_u:system_r:mysqld_t:s0 tcontext=system_u:object_r:mysqld_var_run_t:s0 tclass=dir
# audit2allow -M local < /tmp/avc
******************** IMPORTANT ***********************
To make this policy package active, execute:

semodule -i local.pp

# semodule -i local.pp

#audit2allow -M local -i /var/log/audit/audit.log

httpd access denial, change type to httpd_sys_content_t
chcon -R -t httpd_sys_content_t /var/www/html/

MySQL

Show Databases
mysql> show databases;

Show Status/variables
mysql> show status;

mysql> show variables;
$ mysqladmin variables
$ mysqladmin processlist extended-status -i5

Delete database
mysql> drop database vanilla_db;

Change default mysql database location.
 /etc/my.cnf

Backup
mysqldump -u root -p my_db > my_db.sql

Restore
mysql -p -u root  my_db < my_db.sql

QCache and exam qcache_lowmem_prunes
show  status like "ques%";

show status like "qcache%";

Set up mysql server

Installing:
yum install mysql mysql-server php-mysql

Chkconfig
chkconfig --level 345 mysqld on

Manual start
/etc/init.d/mysqld start
...
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h tortoise password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation
...

Run /usr/bin/mysql_secure_installation and accept all defaults.
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 MySQL
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 MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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]
... 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]
... Success!

By default, MySQL 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]
- Dropping test database...
ERROR 1010 (HY000) at line 1: Error dropping database (can't rmdir './test', errno: 13)
... Failed! Not critical, keep moving...
- 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]
... Success!

Cleaning up...



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

Thanks for using MySQL!


Add vanilla_db and guest user (used for vanilla forum):

mysql -u root -p

mysql> create database vanilla_db;
Query OK, 1 row affected (0.00 sec)

mysql> grant all privileges on vanilla_db.* to guest@localhost identified by 'XXXXXXXX';
Query OK, 0 rows affected (0.00 sec)