Install MySql on CentOS
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
- Login to a terminal as root using one of these options: (su –login | su -l | or: su -)
- Yum and rpm must also be installed and functional (something is seriously wrong if they aren’t)
Doing the Work
- Install mysql mysql-server:
# yum install mysql mysql-server
Loading "priorities" plugin
Loading "changelog" plugin
Loading "fastestmirror" plugin
Loading "allowdowngrade" plugin
Loading "kernel-module" plugin
Loading "fedorakmod" plugin
Loading "installonlyn" plugin
Loading "protectbase" plugin
Setting up Install Process
Setting up repositories
livna 100% |=========================| 1.1 kB 00:00
updates 100% |=========================| 1.2 kB 00:00
core 100% |=========================| 1.1 kB 00:00
extras 100% |=========================| 1.1 kB 00:00
Loading mirror speeds from cached hostfile
Reading repository metadata in from local files
primary.xml.gz 100% |=========================| 1.8 MB 00:06
extras : ################################################## 5594/5594
0 packages excluded due to repository priority protections
0 packages excluded due to repository protections
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for mysql to pack into transaction set.
mysql-5.0.27-1.fc6.i386.r 100% |=========================| 36 kB 00:00
---> Package mysql.i386 0:5.0.27-1.fc6 set to be updated
---> Downloading header for mysql-server to pack into transaction set.
mysql-server-5.0.27-1.fc6 100% |=========================| 33 kB 00:00
---> Package mysql-server.x86_64 0:5.0.27-1.fc6 set to be updated
---> Downloading header for mysql to pack into transaction set.
mysql-5.0.27-1.fc6.x86_64 100% |=========================| 36 kB 00:00
---> Package mysql.x86_64 0:5.0.27-1.fc6 set to be updated
--> Running transaction check
--> Processing Dependency: perl-DBI for package: mysql-server
--> Processing Dependency: perl(DBI) for package: mysql
--> Processing Dependency: perl(DBI) for package: mysql-server
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for perl-DBI to pack into transaction set.
perl-DBI-1.52-1.fc6.x86_6 100% |=========================| 16 kB 00:00
---> Package perl-DBI.x86_64 0:1.52-1.fc6 set to be updated
---> Downloading header for perl-DBD-MySQL to pack into transaction set.
perl-DBD-MySQL-3.0007-1.f 100% |=========================| 8.5 kB 00:00
---> Package perl-DBD-MySQL.x86_64 0:3.0007-1.fc6 set to be updated
--> Running transaction check Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
mysql i386 5.0.27-1.fc6 updates 3.3 M
mysql x86_64 5.0.27-1.fc6 updates 3.3 M
mysql-server x86_64 5.0.27-1.fc6 updates 10 M Installing for dependencies:
perl-DBD-MySQL x86_64 3.0007-1.fc6 core 147 k
perl-DBI x86_64 1.52-1.fc6 core 605 k Transaction Summary
=============================================================================
Install 5 Package(s)
Update 0 Package(s)
Remove 0 Package(s) Total download size: 18 M
Is this ok [y/N]:
- Start MySQL server daemon (mysqld):
# chkconfig --level 2345 mysqld on; service mysqld start
Initializing MySQL database: Installing all prepared tables
Fill help tables To start mysqld at boot time you have to copy support-files/mysql.server
to the right place for your system 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 angstrom password 'new-password'
See the manual for more instructions. You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe & You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:
cd sql-bench ; perl run-all-tests Please report any problems with the /usr/bin/mysqlbug script! The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com
[ OK ]
Starting MySQL: [ OK ]
- Login as root database admin to MySQL server:
# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.0.27 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql>
- Delete ALL users who are not root:
mysql> delete from mysql.user where not (host="localhost" and user="root");
Query OK, 5 rows affected (0.15 sec) mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec) mysql>
- Change root database admin password: (note: once this step is complete you’ll need to login with: mysql -p -u root)
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('mypass'); Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec) mysql>
- Change root username to something less guessable for higher security.
mysql> update mysql.user set user="mydbadmin" where user="root";
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0 mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec) mysql>
- Remove anonymous access to the database(s):
mysql> DELETE FROM mysql.user WHERE User = '';
Query OK, 2 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec) mysql>
- Add a new user with database admin privs for all databases:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'warren'@'localhost' IDENTIFIED BY 'mypass' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec) mysql>
- 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.)
mysql> GRANT ALL PRIVILEGES ON bugzilla.* TO 'warren'@'localhost' IDENTIFIED BY 'mypass';
Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> Alternatively, you can give someone access to only certain privileges by substituting "ALL PRIVILEGES"
with any combination of the following (commas included):
SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES
- Add a MySQL database:
mysql> create database bugzilla;
Query OK, 1 row affected (0.15 sec) mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec) mysql> quit
Bye
- Installing mysql-administrator:
The MySql Administrator packages for Centos 5.x can be found here: MySQL Administrator Packages:
http://people.centos.org/hughesjr/mysql-gui-tools/i386/ Possible Dependencies:
http://centos.karan.org/el5/extras/testing/i386/RPMS/ To install these packages download the desired tools into a directory on your desktop or a directory
on the server, cd into the directory and issue this command: rpm -ivh *.rpm Make sure that the rpms you want to install are the only files in the directory.
- Improving local file security (after saving and exiting remember to: service mysqld restart for changes to take effect):
The next change is to disable the use of LOAD DATA LOCAL INFILE command, which will help to
prevent against unauthorized reading from local files. This matters especially when new SQL
Injection vulnerabilities in PHP applications are found. For that purpose, the following parameter should be added in the [mysqld] section in:
/etc/my.cnf
set-variable=local-infile=0
- Disabling remote access to the MySQL server (after saving and exiting remember to: service mysqld restart for changes to take effect).
This change applies to the 3306/tcp port, on which MySQL listens by default. Because,
according to the initial assumptions, the database will be used only by locally installed PHP
applications, we can freely disable listening on that port. This will limit possibilities of
attacking the MySQL database by direct TCP/IP connections from other hosts. Local communication
will be still possible throw the mysql.sock socket. In order to disable listening on the
mentioned port, the following parameter should be added to the [mysqld] section of /etc/my.cnf: skip-networking If, for some reason, remote access to the database is still required (e.g. to perform remote
data backup), the SSH protocol can be used as follows: (modify to your needs)
backuphost$ ssh mysqlserver /usr/local/mysql/bin/mysqldump -A > backup
Troubleshooting
How to test
- Make sure mysql and mysql server are indeed installed and that they are the correct versions:
# rpm -qa | grep mysql && chkconfig --list | grep mysql
mysql-5.0.27-1.fc6
mysql-5.0.27-1.fc6
mysql-gui-common-1.1.10-3.fc6
mysql-server-5.0.27-1.fc6
mysql-administrator-1.1.10-3.fc6
mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
- Starting mysqld on boot:
# chkconfig --level 2345 mysqld on && service mysqld restart && chkconfig --list | grep mysqld
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
- Clear MySQL scrollback history (so sensitive data such as passwords cannot be seen by others with access):
]# cat /dev/null > ~/.mysql_history
- Show all users in the MySQL Server database:
mysql> select * from mysql.user;
8 rows in set (0.00 sec)
- Delete a user from the MySQL Server database:
mysql> delete from mysql.user where host = "dev.mydomain.com";Query OK, 2 rows affected (0.00 sec)
- Delete a null user (user without a username) from the MySQL Server database:
mysql> delete from mysql.user where user = ' ';
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的更多相关文章
- How to Install MySQL on CentOS 7
CentOS 7的yum源中貌似没有正常安装mysql时的mysql-sever文件,需要去官网上下载 # wget http://dev.mysql.com/get/mysql-communit ...
- Install MySQL on CentOS 7
原文:https://devops.profitbricks.com/tutorials/install-mysql-on-centos-7/ 1.下载mysql 在mysql官网选择适合的mysql ...
- yum install mysql on centos 6.5 zz
http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/07/3003278.html 1.使用yum命令进行mysql的安装 yum list ...
- 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 ...
- 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 ...
- 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 ...
- yum mysql on centos 7
参考:https://www.linode.com/docs/databases/mysql/how-to-install-mysql-on-centos-7 centos 7上没有办法使用yum i ...
- Mysql之CentOS初探
1. 卸载mysql 查看CentOS是否已经安装mysql数据库 rpm -qa | grep mysqlrpm -qa | grep MySQL 如果有,则卸载 // --nodeps表示强制rp ...
- How to install cacti on centos 6
Cacti – Network and performance monitoring tool Cacti is one of best monitoring tool used to monit ...
随机推荐
- hdu-2955(01背包+逆向思维+审题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:注意p和m[i]是被抓的概率,不能直接用,要转换为逃跑的概率,然后将得到的钱视为背包体积再 ...
- c语言中几个常见的库函数strlen、strcmp、strcat、strcpy、strncpy、memset、memcpy、memmove、mmap
1.strlen() 1)计算给定字符串的长度,不包括’\0’在内 unsigned int strlen(const char *s) { assert(NULL != s);//如果条件不满足,则 ...
- 基于图像切换器(imageSwitcher)的支持动画的图片浏览器
利用GridView和ImageSwitcher的基本用法 public class MainActivity extends Activity { int[] imageIds = new int[ ...
- UVa 10269 Adventure of Super Mario (Floyd + DP + BFS)
题意:有A个村庄,B个城市,m条边,从起点到终点,找一条最短路径.但是,有一种工具可以使人不费力的移动L个长度,但始末点必须是城市或村庄.这种工具有k个,每个只能使用一次,并且在城市内部不可使用,但在 ...
- HDU 1087 Super Jumping! Jumping! Jumping! (DP+LIS)
题意:给定一个长度为n的序列,让你求一个和最大递增序列. 析:一看,是不是很像LIS啊,这基本就是一样的,只不过改一下而已,d(i)表示前i个数中,最大的和并且是递增的, 如果 d(j) + a[i] ...
- css3美化滚动条样式
1.改变浏览器默认的滚动条样式 ::-webkit-scrollbar-track-piece { //滚动条凹槽的颜色,还可以设置边框属性 background-color:#f8f8f8; } : ...
- Winfrom 嵌入word、excel实现源码
效果图: winform中嵌入word的方法有多种:调用API,使用webBroser或使用DSOFRAMER控件: API过于繁琐: webbroser读取小文件还行,大文件就太痛苦了: 所以还是选 ...
- [Android]高低API版本兼容之@TargetApi
使用@TargetApi annotaion, 使高版本API的代码在低版本SDK不报错 例如: AsyncTask.THREAD_POOL_EXECUTOR, 这个静态变量是API11才有的, 设置 ...
- 移动 APP 网络优化概述
一般开发一个 APP,会直接调用系统提供的网络请求接口去服务端请求数据,再针对返回的数据进行一些处理,或者使用AFNetworking/OKHttp这样的网络库,管理好请求线程和队列,再自动做一些数据 ...
- nodejs async
官网:https://github.com/caolan/async 流程控制:简化十种常见流程的处理集合处理:如何使用异步操作处理集合中的数据工具类:几个常用的工具类 流程控制 详细说明:http: ...