Installing & Configuring MySQL Server

This Howto will show you how to install MySQL 5.x, start the service, make sure the server starts on reboot, login via terminal, change the root database admin password, change the name of the root user, add a new user with specific privileges to a specific database, add a new DBA, add a new database, remove all anonymous logins, remove all non-root users, added file security steps, disable remote access (via port 3306), purge the scrollback history, and finally the installation of the gui tool mysql-administrator.

Applicable to Centos Versions:

  • Centos 5.x
  • Centos 6.x

Requirements

  1. Login to a terminal as root using one of these options: (su –login | su -l | or: su -)
  2. Yum and rpm must also be installed and functional (something is seriously wrong if they aren’t)

Doing the Work

    1. Install mysql mysql-server:
  1. # yum install mysql mysql-server
  2. Loading "priorities" plugin
  3. Loading "changelog" plugin
  4. Loading "fastestmirror" plugin
  5. Loading "allowdowngrade" plugin
  6. Loading "kernel-module" plugin
  7. Loading "fedorakmod" plugin
  8. Loading "installonlyn" plugin
  9. Loading "protectbase" plugin
  10. Setting up Install Process
  11. Setting up repositories
  12. livna 100% |=========================| 1.1 kB 00:00
  13. updates 100% |=========================| 1.2 kB 00:00
  14. core 100% |=========================| 1.1 kB 00:00
  15. extras 100% |=========================| 1.1 kB 00:00
  16. Loading mirror speeds from cached hostfile
  17. Reading repository metadata in from local files
  18. primary.xml.gz 100% |=========================| 1.8 MB 00:06
  19. extras : ################################################## 5594/5594
  20. 0 packages excluded due to repository priority protections
  21. 0 packages excluded due to repository protections
  22. Parsing package install arguments
  23. Resolving Dependencies
  24. --> Populating transaction set with selected packages. Please wait.
  25. ---> Downloading header for mysql to pack into transaction set.
  26. mysql-5.0.27-1.fc6.i386.r 100% |=========================| 36 kB 00:00
  27. ---> Package mysql.i386 0:5.0.27-1.fc6 set to be updated
  28. ---> Downloading header for mysql-server to pack into transaction set.
  29. mysql-server-5.0.27-1.fc6 100% |=========================| 33 kB 00:00
  30. ---> Package mysql-server.x86_64 0:5.0.27-1.fc6 set to be updated
  31. ---> Downloading header for mysql to pack into transaction set.
  32. mysql-5.0.27-1.fc6.x86_64 100% |=========================| 36 kB 00:00
  33. ---> Package mysql.x86_64 0:5.0.27-1.fc6 set to be updated
  34. --> Running transaction check
  35. --> Processing Dependency: perl-DBI for package: mysql-server
  36. --> Processing Dependency: perl(DBI) for package: mysql
  37. --> Processing Dependency: perl(DBI) for package: mysql-server
  38. --> Processing Dependency: perl-DBD-MySQL for package: mysql-server
  39. --> Restarting Dependency Resolution with new changes.
  40. --> Populating transaction set with selected packages. Please wait.
  41. ---> Downloading header for perl-DBI to pack into transaction set.
  42. perl-DBI-1.52-1.fc6.x86_6 100% |=========================| 16 kB 00:00
  43. ---> Package perl-DBI.x86_64 0:1.52-1.fc6 set to be updated
  44. ---> Downloading header for perl-DBD-MySQL to pack into transaction set.
  45. perl-DBD-MySQL-3.0007-1.f 100% |=========================| 8.5 kB 00:00
  46. ---> Package perl-DBD-MySQL.x86_64 0:3.0007-1.fc6 set to be updated
  47. --> Running transaction check
  48.  
  49. Dependencies Resolved
  50. =============================================================================
  51. Package Arch Version Repository Size
  52. =============================================================================
  53. Installing:
  54. mysql i386 5.0.27-1.fc6 updates 3.3 M
  55. mysql x86_64 5.0.27-1.fc6 updates 3.3 M
  56. mysql-server x86_64 5.0.27-1.fc6 updates 10 M
  57.  
  58. Installing for dependencies:
  59. perl-DBD-MySQL x86_64 3.0007-1.fc6 core 147 k
  60. perl-DBI x86_64 1.52-1.fc6 core 605 k
  61.  
  62. Transaction Summary
  63. =============================================================================
  64. Install 5 Package(s)
  65. Update 0 Package(s)
  66. Remove 0 Package(s)
  67.  
  68. Total download size: 18 M
  69. Is this ok [y/N]:
    1. Start MySQL server daemon (mysqld):
  1. # chkconfig --level 2345 mysqld on; service mysqld start
  2. Initializing MySQL database: Installing all prepared tables
  3. Fill help tables
  4.  
  5. To start mysqld at boot time you have to copy support-files/mysql.server
  6. to the right place for your system
  7.  
  8. PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
  9. To do so, start the server, then issue the following commands:
  10. /usr/bin/mysqladmin -u root password 'new-password'
  11. /usr/bin/mysqladmin -u root -h angstrom password 'new-password'
  12. See the manual for more instructions.
  13.  
  14. You can start the MySQL daemon with:
  15. cd /usr ; /usr/bin/mysqld_safe &
  16.  
  17. You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:
  18. cd sql-bench ; perl run-all-tests
  19.  
  20. Please report any problems with the /usr/bin/mysqlbug script!
  21.  
  22. The latest information about MySQL is available on the web at
  23.  
  24. http://www.mysql.com
  25.  
  26. Support MySQL by buying support/licenses at http://shop.mysql.com
  27. [ OK ]
  28. Starting MySQL: [ OK ]
    1. Login as root database admin to MySQL server:
  1. # mysql -u root
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 2 to server version: 5.0.27
  4.  
  5. Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  6.  
  7. mysql>
    1. Delete ALL users who are not root:
  1. mysql> delete from mysql.user where not (host="localhost" and user="root");
  2. Query OK, 5 rows affected (0.15 sec)
  3.  
  4. mysql> FLUSH PRIVILEGES;
  5. Query OK, 0 rows affected (0.00 sec)
  6.  
  7. mysql>
    1. Change root database admin password: (note: once this step is complete you’ll need to login with: mysql -p -u root)
  1. mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('mypass');
  2.  
  3. Query OK, 0 rows affected (0.00 sec)
  4.  
  5. mysql> FLUSH PRIVILEGES;
  6. Query OK, 0 rows affected (0.00 sec)
  7.  
  8. mysql>
    1. Change root username to something less guessable for higher security.
  1. mysql> update mysql.user set user="mydbadmin" where user="root";
  2. Query OK, 2 rows affected (0.00 sec)
  3. Rows matched: 2 Changed: 2 Warnings: 0
  4.  
  5. mysql> FLUSH PRIVILEGES;
  6. Query OK, 0 rows affected (0.00 sec)
  7.  
  8. mysql>
    1. Remove anonymous access to the database(s):
  1. mysql> DELETE FROM mysql.user WHERE User = '';
  2. Query OK, 2 rows affected (0.00 sec)
  3.  
  4. mysql> FLUSH PRIVILEGES;
  5. Query OK, 0 rows affected (0.00 sec)
  6.  
  7. mysql>
    1. Add a new user with database admin privs for all databases:
  1. mysql> GRANT ALL PRIVILEGES ON *.* TO 'warren'@'localhost' IDENTIFIED BY 'mypass' WITH GRANT OPTION;
  2. Query OK, 0 rows affected (0.00 sec)
  3.  
  4. mysql> FLUSH PRIVILEGES;
  5. Query OK, 0 rows affected (0.00 sec)
  6.  
  7. mysql>
    1. Add a new user with database admin privs for a specific database, in this case the database is called “bugzilla”: (note: The ‘bugzilla’ database must first be added, see below.)
  1. mysql> GRANT ALL PRIVILEGES ON bugzilla.* TO 'warren'@'localhost' IDENTIFIED BY 'mypass';
  2. Query OK, 0 rows affected (0.00 sec)
  3.  
  4. mysql> FLUSH PRIVILEGES;
  5. Query OK, 0 rows affected (0.00 sec)
  6. mysql>
  7.  
  8. Alternatively, you can give someone access to only certain privileges by substituting "ALL PRIVILEGES"
  9. with any combination of the following (commas included):
  10. SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES
    1. Add a MySQL database:
  1. mysql> create database bugzilla;
  2. Query OK, 1 row affected (0.15 sec)
  3.  
  4. mysql> FLUSH PRIVILEGES;
  5. Query OK, 0 rows affected (0.00 sec)
  6.  
  7. mysql> quit
  8. Bye
    1. Installing mysql-administrator:
  1. The MySql Administrator packages for Centos 5.x can be found here:
  2.  
  3. MySQL Administrator Packages:
  4. http://people.centos.org/hughesjr/mysql-gui-tools/i386/
  5.  
  6. Possible Dependencies:
  7. http://centos.karan.org/el5/extras/testing/i386/RPMS/
  8.  
  9. To install these packages download the desired tools into a directory on your desktop or a directory
  10. on the server, cd into the directory and issue this command: rpm -ivh *.rpm
  11.  
  12. Make sure that the rpms you want to install are the only files in the directory.
    1. Improving local file security (after saving and exiting remember to: service mysqld restart for changes to take effect):
  1. The next change is to disable the use of LOAD DATA LOCAL INFILE command, which will help to
  2. prevent against unauthorized reading from local files. This matters especially when new SQL
  3. Injection vulnerabilities in PHP applications are found.
  4.  
  5. For that purpose, the following parameter should be added in the [mysqld] section in:
  6. /etc/my.cnf

  7. set-variable=local-infile=0
    1. Disabling remote access to the MySQL server (after saving and exiting remember to: service mysqld restart for changes to take effect).
  1. This change applies to the 3306/tcp port, on which MySQL listens by default. Because,
  2. according to the initial assumptions, the database will be used only by locally installed PHP
  3. applications, we can freely disable listening on that port. This will limit possibilities of
  4. attacking the MySQL database by direct TCP/IP connections from other hosts. Local communication
  5. will be still possible throw the mysql.sock socket. In order to disable listening on the
  6. mentioned port, the following parameter should be added to the [mysqld] section of /etc/my.cnf:
  7.  
  8. skip-networking
  9.  
  10. If, for some reason, remote access to the database is still required (e.g. to perform remote
  11. data backup), the SSH protocol can be used as follows:
  12.  
  13. (modify to your needs)
  14. backuphost$ ssh mysqlserver /usr/local/mysql/bin/mysqldump -A > backup

Troubleshooting

How to test

    1. Make sure mysql and mysql server are indeed installed and that they are the correct versions:
  1. # rpm -qa | grep mysql && chkconfig --list | grep mysql
  2. mysql-5.0.27-1.fc6
  3. mysql-5.0.27-1.fc6
  4. mysql-gui-common-1.1.10-3.fc6
  5. mysql-server-5.0.27-1.fc6
  6. mysql-administrator-1.1.10-3.fc6
  7. mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
    1. Starting mysqld on boot:
  1. # chkconfig --level 2345 mysqld on && service mysqld restart && chkconfig --list | grep mysqld
  2. Stopping MySQL: [ OK ]
  3. Starting MySQL: [ OK ]
  4. mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
    1. Clear MySQL scrollback history (so sensitive data such as passwords cannot be seen by others with access):
  1. ]# cat /dev/null > ~/.mysql_history
    1. Show all users in the MySQL Server database:
  1. mysql> select * from mysql.user;
  2. 8 rows in set (0.00 sec)
    1. Delete a user from the MySQL Server database:
  1. mysql> delete from mysql.user where host = "dev.mydomain.com";Query OK, 2 rows affected (0.00 sec)
    1. Delete a null user (user without a username) from the MySQL Server database:
  1. mysql> delete from mysql.user where user = ' ';
  2. Query OK, 1 rows affected (0.00 sec)

Common problems and fixes

Problem: User has not properly logged in with roots environment.

Fix: (switch to root with one of the following methods):
su –login
su -l
su -

More Information

Disclaimer

We test this stuff on our own machines, really we do. But you may run into problems, if you do, come to #centoshelp on irc.freenode.net

This has been tested on Centos 5.x and 6.x

Install MySql on CentOS的更多相关文章

  1. How to Install MySQL on CentOS 7

    CentOS 7的yum源中貌似没有正常安装mysql时的mysql-sever文件,需要去官网上下载   # wget http://dev.mysql.com/get/mysql-communit ...

  2. Install MySQL on CentOS 7

    原文:https://devops.profitbricks.com/tutorials/install-mysql-on-centos-7/ 1.下载mysql 在mysql官网选择适合的mysql ...

  3. yum install mysql on centos 6.5 zz

    http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/07/3003278.html 1.使用yum命令进行mysql的安装 yum list ...

  4. How to install MySQL on CentOS

    1)chekc centos中是否安装了MySQL [root@localhost MySQL]# rpm -qa | grep mariadb mariadb-libs-5.5.52-1.el7.x ...

  5. Install Apache, PHP And MySQL On CentOS 7 (LAMP)

    This tutorial shows how you can install an Apache2 webserver on a CentOS 7.0 server with PHP5 suppor ...

  6. Install MySQL 5.7 on Fedora 25/24, CentOS/RHEL 7.3/6.8/5.11

    MySQL is a relational database management system (RDBMS) that runs as a server providing multi-user ...

  7. yum mysql on centos 7

    参考:https://www.linode.com/docs/databases/mysql/how-to-install-mysql-on-centos-7 centos 7上没有办法使用yum i ...

  8. Mysql之CentOS初探

    1. 卸载mysql 查看CentOS是否已经安装mysql数据库 rpm -qa | grep mysqlrpm -qa | grep MySQL 如果有,则卸载 // --nodeps表示强制rp ...

  9. How to install cacti on centos 6

    Cacti – Network and performance monitoring tool   Cacti is one of best monitoring tool used to monit ...

随机推荐

  1. py-函数基础

    定义: 函数是指将一组语句的集合通过一个名字(函数名)封装起来,要想执行这个函数,只需调用其函数名即可 特性: 1.减少重复代码2.使程序变的可扩展3.使程序变得易维护 函数参数 形参变量 只有在被调 ...

  2. Java static说明

    class Person{ String name;//成员变量,实例变量 static String country = "CN";//静态变量.类变量 public void ...

  3. python 求最大子序列

     动态规划的本质,是对问题状态的定义和状态转移方程的定义.dynamic programming is a method for solving a complex problem by breaki ...

  4. siganl tappII的应用及MATLAB调用

    1.在应用SIGNAL TAPPII时一定要把不用的端口设置为输入三态,否则观察不到数据. 2.用SIGNAL TAPII 观察数据时双向是观察不到数据的,但模块内部用于传输双向口数据的寄存器可以看到 ...

  5. Apache Struts 2 Documentation Big Picture

    http://struts.apache.org/docs/big-picture.html 1. HttpServletRequest 穿越各个过滤器到达FilterDispatcher(这个已经不 ...

  6. RabbitMQ 初探

    有哪些优点 可靠性:RabbitMQ 提供了多种技术可以让你在性能和可靠性之间进行权衡.这些技术包括持久性.投递确认.发布者证实和高可用性. 灵活的路由:提供了多种内置交换机类型.如果你有更复杂的路由 ...

  7. Java中取两位小数

    请参考下面函数: private String getFormated(String s){        float f=Float.parseFloat(s);        java.text. ...

  8. ibatIs中的isNotNull、isEqual、isEmpty

    isNull判断property字段是否是null,用isEmpty更方便,包含了null和空字符串 例子一:isEqual相当于equals,数字用得多些,一般都是判断状态值<isEqual ...

  9. Linux服务器目录空间不足解决措施

      一般情况下工作环境中我们的服务或数据库文件都会存储在一个单独挂载的分区中,一般占空间比较大的大多就是服务的运行日志以及数据库文件,当我们分区的可用空间不足时就需要我们对分区进行扩容,或者找其它方法 ...

  10. 使用hadoop-daemon.sh 启动bootstrapStandby nameNode异常

    使用hadoop-daemon.sh 启动bootstrapStandby nameNode异常 启动bootstrapStandby nameNode时,直接通过ssh 过去执行该命令,一直无法成功 ...