操作系统:CentOS release 5.10 (Final)
文件准备:
MySQL-server-community-5.1.73-1.rhel5.i386.rpm
MySQL-client-community-5.1.73-1.rhel5.i386.rpm
一、安装MySQL
rpm包安装:
切换到包所在目录,执行:
rpm -i MySQL-server-community-5.1.73-1.rhel5.i386.rpm rpm -i MySQL-client-community-5.1.73-1.rhel5.i386.rpm
完成后MySQL的*安装目录为/usr。注意,如果只是安装了MySQL-server的话,在这些路径中像mysql、mysqladmin等是没有的,也是无法使用的。
/etc/init.d/mysql
/etc/logrotate.d/mysql
/etc/my.cnf
/etc/mysqlmanager.passwd
/usr/bin/innochecksum
/usr/bin/my_print_defaults
/usr/bin/myisam_ftdump
/usr/bin/myisamchk
/usr/bin/myisamlog
/usr/bin/myisampack
/usr/bin/mysql_convert_table_format
/usr/bin/mysql_fix_extensions
/usr/bin/mysql_fix_privilege_tables
/usr/bin/mysql_install_db
/usr/bin/mysql_secure_installation
/usr/bin/mysql_setpermission
/usr/bin/mysql_tzinfo_to_sql
/usr/bin/mysql_upgrade
/usr/bin/mysql_zap
/usr/bin/mysqlbug
/usr/bin/mysqld_multi
/usr/bin/mysqld_safe
/usr/bin/mysqldumpslow
/usr/bin/mysqlhotcopy
/usr/bin/mysqltest
/usr/bin/perror
/usr/bin/replace
/usr/bin/resolve_stack_dump
/usr/bin/resolveip
/usr/lib/mysql/mysqld-debug.sym
/usr/lib/mysql/mysqld.sym
/usr/lib/mysql/plugin/ha_innodb_plugin.so
/usr/lib/mysql/plugin/ha_innodb_plugin.so.0
/usr/lib/mysql/plugin/ha_innodb_plugin.so.0.0.0
/usr/sbin/mysqld
/usr/sbin/mysqld-debug
/usr/sbin/mysqlmanager
/usr/sbin/rcmysql
/usr/share/doc/MySQL-server-community-5.1.73
/usr/share/doc/MySQL-server-community-5.1.73/COPYING
/usr/share/doc/MySQL-server-community-5.1.73/README
/usr/share/doc/MySQL-server-community-5.1.73/my-huge.cnf
/usr/share/doc/MySQL-server-community-5.1.73/my-innodb-heavy-4G.cnf
/usr/share/doc/MySQL-server-community-5.1.73/my-large.cnf
/usr/share/doc/MySQL-server-community-5.1.73/my-medium.cnf
/usr/share/doc/MySQL-server-community-5.1.73/my-small.cnf
/usr/share/info/mysql.info.gz
/usr/share/man/man1/innochecksum.1.gz
/usr/share/man/man1/my_print_defaults.1.gz
/usr/share/man/man1/myisam_ftdump.1.gz
/usr/share/man/man1/myisamchk.1.gz
/usr/share/man/man1/myisamlog.1.gz
/usr/share/man/man1/myisampack.1.gz
/usr/share/man/man1/mysql.server.1.gz
/usr/share/man/man1/mysql_convert_table_format.1.gz
/usr/share/man/man1/mysql_fix_extensions.1.gz
/usr/share/man/man1/mysql_fix_privilege_tables.1.gz
/usr/share/man/man1/mysql_install_db.1.gz
/usr/share/man/man1/mysql_secure_installation.1.gz
/usr/share/man/man1/mysql_setpermission.1.gz
/usr/share/man/man1/mysql_tzinfo_to_sql.1.gz
/usr/share/man/man1/mysql_upgrade.1.gz
/usr/share/man/man1/mysql_zap.1.gz
/usr/share/man/man1/mysqlbug.1.gz
/usr/share/man/man1/mysqld_multi.1.gz
/usr/share/man/man1/mysqld_safe.1.gz
/usr/share/man/man1/mysqldumpslow.1.gz
/usr/share/man/man1/mysqlhotcopy.1.gz
/usr/share/man/man1/mysqlman.1.gz
/usr/share/man/man1/mysqltest.1.gz
/usr/share/man/man1/perror.1.gz
/usr/share/man/man1/replace.1.gz
/usr/share/man/man1/resolve_stack_dump.1.gz
/usr/share/man/man1/resolveip.1.gz
/usr/share/man/man8/mysqld.8.gz
/usr/share/man/man8/mysqlmanager.8.gz
/usr/share/mysql
/usr/share/mysql/ChangeLog
/usr/share/mysql/SELinux
/usr/share/mysql/SELinux/RHEL4
/usr/share/mysql/SELinux/RHEL4/mysql.fc
/usr/share/mysql/SELinux/RHEL4/mysql.te
/usr/share/mysql/binary-configure
/usr/share/mysql/charsets
/usr/share/mysql/charsets/Index.xml
/usr/share/mysql/charsets/README
/usr/share/mysql/charsets/armscii8.xml
/usr/share/mysql/charsets/ascii.xml
/usr/share/mysql/charsets/cp1250.xml
/usr/share/mysql/charsets/cp1251.xml
/usr/share/mysql/charsets/cp1256.xml
/usr/share/mysql/charsets/cp1257.xml
/usr/share/mysql/charsets/cp850.xml
/usr/share/mysql/charsets/cp852.xml
/usr/share/mysql/charsets/cp866.xml
/usr/share/mysql/charsets/dec8.xml
/usr/share/mysql/charsets/geostd8.xml
/usr/share/mysql/charsets/greek.xml
/usr/share/mysql/charsets/hebrew.xml
/usr/share/mysql/charsets/hp8.xml
/usr/share/mysql/charsets/keybcs2.xml
/usr/share/mysql/charsets/koi8r.xml
/usr/share/mysql/charsets/koi8u.xml
/usr/share/mysql/charsets/latin1.xml
/usr/share/mysql/charsets/latin2.xml
/usr/share/mysql/charsets/latin5.xml
/usr/share/mysql/charsets/latin7.xml
/usr/share/mysql/charsets/macce.xml
/usr/share/mysql/charsets/macroman.xml
/usr/share/mysql/charsets/swe7.xml
/usr/share/mysql/config.huge.ini
/usr/share/mysql/config.medium.ini
/usr/share/mysql/config.small.ini
/usr/share/mysql/czech
/usr/share/mysql/czech/errmsg.sys
/usr/share/mysql/danish
/usr/share/mysql/danish/errmsg.sys
/usr/share/mysql/dutch
/usr/share/mysql/dutch/errmsg.sys
/usr/share/mysql/english
/usr/share/mysql/english/errmsg.sys
/usr/share/mysql/errmsg.txt
/usr/share/mysql/estonian
/usr/share/mysql/estonian/errmsg.sys
/usr/share/mysql/fill_help_tables.sql
/usr/share/mysql/french
/usr/share/mysql/french/errmsg.sys
/usr/share/mysql/german
/usr/share/mysql/german/errmsg.sys
/usr/share/mysql/greek
/usr/share/mysql/greek/errmsg.sys
/usr/share/mysql/hungarian
/usr/share/mysql/hungarian/errmsg.sys
/usr/share/mysql/italian
/usr/share/mysql/italian/errmsg.sys
/usr/share/mysql/japanese
/usr/share/mysql/japanese/errmsg.sys
/usr/share/mysql/korean
/usr/share/mysql/korean/errmsg.sys
/usr/share/mysql/mi_test_all
/usr/share/mysql/mi_test_all.res
/usr/share/mysql/my-huge.cnf
/usr/share/mysql/my-innodb-heavy-4G.cnf
/usr/share/mysql/my-large.cnf
/usr/share/mysql/my-medium.cnf
/usr/share/mysql/my-small.cnf
/usr/share/mysql/mysql-log-rotate
/usr/share/mysql/mysql.server
/usr/share/mysql/mysql_fix_privilege_tables.sql
/usr/share/mysql/mysql_system_tables.sql
/usr/share/mysql/mysql_system_tables_data.sql
/usr/share/mysql/mysql_test_data_timezone.sql
/usr/share/mysql/mysqld_multi.server
/usr/share/mysql/ndb-config-2-node.ini
/usr/share/mysql/norwegian
/usr/share/mysql/norwegian-ny
/usr/share/mysql/norwegian-ny/errmsg.sys
/usr/share/mysql/norwegian/errmsg.sys
/usr/share/mysql/polish
/usr/share/mysql/polish/errmsg.sys
/usr/share/mysql/portuguese
/usr/share/mysql/portuguese/errmsg.sys
/usr/share/mysql/romanian
/usr/share/mysql/romanian/errmsg.sys
/usr/share/mysql/russian
/usr/share/mysql/russian/errmsg.sys
/usr/share/mysql/serbian
/usr/share/mysql/serbian/errmsg.sys
/usr/share/mysql/slovak
/usr/share/mysql/slovak/errmsg.sys
/usr/share/mysql/spanish
/usr/share/mysql/spanish/errmsg.sys
/usr/share/mysql/swedish
/usr/share/mysql/swedish/errmsg.sys
/usr/share/mysql/ukrainian
/usr/share/mysql/ukrainian/errmsg.sys
/usr/bin/msql2mysql
/usr/bin/mysql
/usr/bin/mysql_find_rows
/usr/bin/mysql_waitpid
/usr/bin/mysqlaccess
/usr/bin/mysqladmin
/usr/bin/mysqlbinlog
/usr/bin/mysqlcheck
/usr/bin/mysqldump
/usr/bin/mysqlimport
/usr/bin/mysqlshow
/usr/bin/mysqlslap
/usr/share/man/man1/msql2mysql.1.gz
/usr/share/man/man1/mysql.1.gz
/usr/share/man/man1/mysql_find_rows.1.gz
/usr/share/man/man1/mysql_waitpid.1.gz
/usr/share/man/man1/mysqlaccess.1.gz
/usr/share/man/man1/mysqladmin.1.gz
/usr/share/man/man1/mysqlbinlog.1.gz
/usr/share/man/man1/mysqlcheck.1.gz
/usr/share/man/man1/mysqldump.1.gz
/usr/share/man/man1/mysqlimport.1.gz
/usr/share/man/man1/mysqlshow.1.gz
/usr/share/man/man1/mysqlslap.1.gz
rpm -ql MySQL-server-community-5.1.73-1.rhel5 MySQL-client-community-5.1.73-1.rhel5
二、安装完成后的相关配置
1.运行mysql_install_db 程序设置含有确定如何让用户连接服务器的权限的初始MySQL授权表。
/usr/bin/mysql_install_db --user=root
mysql_install_db脚本创建数据目录、拥有所有数据库权限的mysql数据库和可以用来测试MySQL的test数据库。脚本为root账户和匿名用户账户创建 授权表条目。
2.启动数据库。
/usr/bin/mysqld_safe --user=mysql &
3.配置数据库
为数据库设定一个密码(初始为空):
/usr/bin/mysqladmin -u root password 'new-password'
卸掉test数据库:
/usr/bin/mysqladmin -u root drop test
以上两个操作可以由mysql_secure_installation脚本代替:
/usr/bin/mysql_secure_installation
其功能包括:
Change the root password?
Remove anonymous users?
Disallow root login remotely?
Remove test database and access to it?
Reload privilege tables now?
4.关闭数据库
/etc/init.d/mysql stop
或
mysqadmin shutdown -uroot -p
5.自动启动数据库
如果④中/etc/init.d/mysql存在或有效,则数据库很可能是已经自动启动的,用以下方法确认:
[root@localhost ~]# chkconfig --list | grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
如果能够列出mysql的启动状态,而且至少3和4为on,则说明mysql能够自动启动。如不能,接着配置:
cd /usr/share/mysql/ cp mysql.server /etc/init.d/mysql chmod +x /etc/init.d/mysql chkconfig --addMySQL chkconfig --level 345MySQL on
在配置自动启动数据库可能会遇到的问题:
当执行
/etc/init.d/mysql
时出现
Starting MySQL.Manager of pid-file quit without updating file [Failed]
查询日志:
cat /var/lib/mysql/localhost.localdomain.err
有错误
/usr/sbin/mysqld: File './mysql-bin.index' not found (Errcode: 13)
140507 21:38:01 [ERROR] Aborting
而这时,执行
/etc/init.d/mysql --user=root
带上参数user是没问题的(--user=root或--user=mysql)
解决办法:
chgrp -R mysql /var/lib/mysql/
chown -R mysql /var/lib/mysql/
/var/lib/mysql/ 是mysql-bin.index所在的文件夹。
6.匿名账户
①为匿名用户指定密码,可以用SET PASSWORD或UPDATE。在两种情况中,一定要使用PASSWORD()函数为密
码加密。
使用SET PASSWORD方法:
shell> mysql -u root
mysql> SET PASSWORD FOR ''@'localhost' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR ''@'host_name' = PASSWORD('newpwd');
使用UPDATE直接修改用户表:
shell> mysql -u root
mysql> UPDATE mysql.user SET Password = PASSWORD('newpwd')
-> WHERE User = '';
mysql> FLUSH PRIVILEGES;
在user表中直接使用UPDATE更新密码后,必须让服务器用FLUSH PRIVILEGES重新读授权表。否则,重新启动服务器
前,不会使用更改。
②删除匿名账户
shell> mysql -u root
mysql> DELETE FROM mysql.user WHERE User = '';
mysql> FLUSH PRIVILEGES;
7.为root账户指定密码
①使用SET PASSWORD语句:
shell> mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'host_name' = PASSWORD('newpwd');
②使用mysqladmin命令行客户端程序:
shell> mysqladmin -u root password "newpwd"
shell> mysqladmin -u root -h host_name password "newpwd"
③使用UPDATE语句:
shell> mysql -u root
mysql> UPDATE mysql.user SET Password = PASSWORD('newpwd')
-> WHERE User = 'root';
mysql> FLUSH PRIVILEGES;
6.远程连接
①MySQL出于安全因素考虑,默认配置只允许本地登录,打开MySQL配置文件 /etc/mysql/my.cnf,找到 bind-address = 127.0.0.1 修改为 bind-address = 0.0.0.0;
②添加一个远程用户,grant all on *.* to 'userRemote'@'192.168.1.111' identified by '123456' with grant option;
grant all on *.* to 'userRemote'@'192.168.1.111' identified by '' with grant option
这样userRemote就可以从地址192.168.1.111来登录MySQL,如果想不限IP,可以将IP地址设为%,这样这个用户从任意地址都可以访问。
③打开对应防火墙(临时),iptables -I INPUT 2 -p tcp --dport 3306 -j ACCEPT。
iptables -I INPUT -p tcp --dport -j ACCEPT
参考与链接:
MySQL5.1参考手册:http://dev.mysql.com/doc/refman/5.1/zh/index.html
MySQL5.1下载地址:http://dev.mysql.com/downloads/mysql/5.1.html#downloads