1 安装MySQL数据库
先从MySQL官网下载MySQL,然后进入所下载的安装文件所在目录,运行如下命令进行安装,其中MySQL-server-community-5156-1rhel5i386rpm为刚刚下载的MySQL数据库服务器的rpm包,然后使用/etc/rcd/initd/mysqlrestart命令重启MySQL服务:
[root@localhost ~]# rpm -ivh MySQL-server-community-5156-1rhel5i386rpm
[root@localhost ~]# /etc/rcd/initd/mysql restart
Shutting down MySQL[确定]
Starting MySQL[确定]
2 配置MySQL数据库字符集
备注:配置MySQL数据库字符集的目的是方便的使用数据库,无需在每次连接的时候都要临时设置数据库字符集的,个人不建议采用这种方法,真正的工程项目都应该在连接数据库时临时设置数据库字符集,如此才便于系统的移植,而且又不会影响数据库服务器中的其他数据库的使用!
安装完成之后,需要配置MySQL的字符集配置,首先需要查找MySQL的配置文件的位置,由于MySQL的配置文件名是以cnf结尾的,因此可用如下命令进行查找:
[root@localhost ~]# find / -iname 'cnf' -print
/usr/share/mysql/my-largecnf
/usr/share/mysql/my-mediumcnf
/usr/share/mysql/my-innodb-heavy-4Gcnf
/usr/share/mysql/my-hugecnf
/usr/share/mysql/my-smallcnf
/usr/share/doc/MySQL-server-community-5156/my-largecnf
/usr/share/doc/MySQL-server-community-5156/my-mediumcnf
/usr/share/doc/MySQL-server-community-5156/my-innodb-heavy-4Gcnf
/usr/share/doc/MySQL-server-community-5156/my-hugecnf
/usr/share/doc/MySQL-server-community-5156/my-smallcnf
/etc/pki/tls/opensslcnf
输入完命令“find / -iname 'cnf'-print”回车后,屏幕便显示搜索到的MySQL配置文件,然后拷贝my-largecnf、my-mediumcnf 、my-innodb-heavy-4Gcnf 、my-hugecnf、my-smallcnf中任意的一个到/etc目录下,并命名为mycnf,其命令如下所示:
[root@localhost ~]# cp /usr/share/mysql/my-mediumcnf /etc/mycnf
[root@localhost ~]# vi /etc/mycnf
然后,使用vi编辑器修改/etc/mycnf文件,在[client]下添加: “default-character-set=gb2312”;在[mysqld]下添加:“default-character-set=gb2312”。如下所示:
# The following options will be passed to all MySQL clients
[client]
default-character-set=gb2312
#password = your_password
port = 3306
socket = /var/lib/mysql/mysqlsock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
default-character-set=gb2312
port = 3306
socket = /var/lib/mysql/mysqlsock
skip-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
按一下Esc键,输入“:wq”后回车保存配置文件,输入“/etc/rcd/initd/mysqlrestart”重启MySQL服务,如下所示:
[root@localhost ~]# /etc/rcd/initd/mysql restart
Shutting down MySQL[确定]
Starting MySQL[确定]
最后,我们来验证MySQL服务器配置是否成功,首先登录MySQL,输入“mysql –uroot -p”回车,系统提示输入密码,登录成功后进入MySQL命令模式,如下所示:
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor Commands end with ; or \g
Your MySQL connection id is 2
Server version: 5156-community-log MySQL Community Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates All rights reserved
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates Other names may be trademarks of their respective
owners
Type 'help;' or '\h' for help Type '\c' to clear the current input statement
mysql>
在MySQL命令模式下分别输入“show variables like'collation_%';”、“show variables like 'character_set_%';”回车后显示字符集设置,如下所示:
mysql> show variables like 'collation_%';
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | gb2312_chinese_ci |
| collation_database | gb2312_chinese_ci |
| collation_server | gb2312_chinese_ci |
+----------------------+-------------------+
3 rows in set (005 sec)
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | gb2312 |
| character_set_connection | gb2312 |
| character_set_database | gb2312 |
| character_set_filesystem | binary |
| character_set_results | gb2312 |
| character_set_server | gb2312 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (000 sec)
mysql>
根据以上查询结果可知我们设置的MySQL数据库配置信息已经生效,至此完成MySQL的服务器的安装与配置。
3关于MySQL数据库的一些注意事项
31 远程连接mysql速度慢
解决方法:
在MySQL服务器的配置(/etc/mycnf)中增加一个如下配置后速度飞快。
[mysqld]
skip-name-resolve
备注:这样就能禁用DNS解析,连接速度会快很多。不过,这样的话就不能在MySQL的授权表中使用主机名了而只能用ip格式。
32 重启数据库后,发现无需密码(或者任何密码)即可以连接
解决方法:
检查你的MySQL配置文件(/etc/mycnf)中是不是多了一条语句:“skip-grant-tables”,删除(注释)该语句,重新配置MySQL密码,再次重启MySQL服务即可!
备注:若使用skip-grant-tables系统将对任何用户的访问不做任何访问控制,但可以用 mysqladmin flush-privileges或mysqladmin reload来开启访问控制;默认情况是show databases语句对所有用户开放,如果mysql服务器没有开远程帐户,就在/etc/mycnf里面加上skip-grant-tables。
以上就是关于MySql怎么安装全部的内容,包括:MySql怎么安装、如何安装mysql数据库、mysql安装教程5.5等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)