---
title: "linux  安装并配置 免安装版的MYSQL  "
author: "yangrenjun"
date: "2012-02-24T17:37:41Z"
tags: []
categories: ["数据库"]
slug: "linux-mysql"
draft: false
lastmod: "2012-03-23T11:14:56Z"
id: 1422635
url: "https://yangrenjun.iteye.com/blog/1422635"
---

第一步 到官网下载 免安装包（估计170到180M)
     http://dev.mysql.com/doc/refman/5.1/en/binary-installation.html

第二步 将安装包(mysql-5.5.21-linux2.6-x86_64.tar.gz),注意我是x86_64bit


第三步 确定要安装目录：我的目录 /usr/local/mysql,数据库存放的位置可以随意放，但是要在 mysql.service 进行配置, 如下设置：
basedir=/usr/local/iaas_mini/mysql

我编写了一个脚本：大体内容如下。具体可以参看官方网站上的配置；就知道我脚本写的是什么啦；
vi mysql_run.sh 


#!/bin/sh

#创建用户组
#创建用户并将其用户mysql加入到组mysql中
groupadd mysql
useradd -r -g mysql mysql

MYSQL_PATH=/usr/local/mysql
cd $MYSQL_PATH

#echo `pwd`

#设置用户能够访问mysql目录
chown -R  mysql .
#设置组用户能够访问mysql目录
chgrp -R  mysql .
#初始化数据库用的
$MYSQL_BASE/scripts/mysql_install_db --user=mysql
#设置ROOT用户访问mysql目录
chown -R root .
chown -R mysql data
#启动mysql 服务
$MYSQL_PATH/bin/mysqld_safe --user=mysql &
××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××

以下是安装MYSQL到网上找到解决的资料：

MYSQL官方网站：

1.To install and use a MySQL binary distribution, the basic command sequence looks like this: 
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
# Next command is optional
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server

运行mysql
#./bin/mysqld_safe --basedir=/usr/local/mysql --user=mysql&

服务启动查看 3306是否启动；

用root进行登录
# ./mysql -u root -p

为了方便起见，我们建立几个链接文件到/sbin中，以免每次要到 mysql中运行程序：

$ ln -s /usr/local/mysql/bin/mysql /sbin/mysql
$ ln -s /usr/local/mysql/bin/mysqladmin /sbin/mysqladmin

让mysql开机可以随系统启动；

$ cp support-files/mysql.server /etc/rc.d/init.d/mysqld

$修改mysqld中的 pid_file的目录！
当然，目录随意最好是和已经启动的PID目录一致
$ chkconfig ――add mysqld
$ chkconfig ――level 345 mysqld on

验证上述操作的正确性，运行：
$ /etc/rc.d/init.d/mysqld restart
$ service mysqld restart

4、mysql的安全设置
$ mysqladmin -uroot password "youpassword" #设置root帐户的密码
$ mysql -uroot -p

mysql>use mysql;
mysql>delete from user where password="";#删除用于本机匿名连接的空密码帐号
mysql>flush privileges;
mysql>quit        

为了能让远程的用户访问数据库，还要添加远程用户。
$ mysql -p
Enter password:*****
mysql>use mysql
mysql>grant all privileges on *.* totest@"192.168.0.%" identified by "test" with grant option;
mysql>quit;

这样就建立了一个超级用户test，可以在本地局域网的任何地方连接，权限很大但密码很弱智，我们不想这样，但是此时，用户的权限已经开始生效了。
如果你手工修改授权表，要：mysql>FLUSH PRIVILEGES;
或者$ mysqladminflush-privileges -p
此外，全局权限的改变和口令改变在下一次客户连接时生效，
表和列权限在客户的下一次请求时生效，
数据库权限改变在下一个 USEdb_name 命令生效。
用 mysqlcc 修改 test 用户的权限，由于我不想让这个用户破坏我的数据，所以在 user 表中。
root@guan-desktop:/usr/local/mysql# bin/mysql_install_db--user=mysql











2.linux远程连接数据库错误 ERROR 2003 (HY000): Can't connect to MySQL server

关掉防火墙试试

# /etc/init.d/iptables stop

Flushing firewall rules: 
Setting chains to policy ACCEPT: filter 
Unloading iptables modules: 
# chkconfig iptables off

3.则会报出ERROR 1130 (HY000): Host '211.87.***.***'is not allowed to connect to this MySQL server提示信息，不能远程连接数据库。

 #mysql
 myqsl> grant all privileges on *.* to 'root'@’%' identified by '123456';
mysql>flush privileges;
mysql>exit;
 
4.MySQL 错误1418 的原因分析及解决方法  
解决方法：

解决办法也有两种，
第一种是在创建子程序(存储过程、函数、触发器)时，声明为DETERMINISTIC或NO SQL与READS SQL DATA中的一个，
例如:
CREATE DEFINER = CURRENT_USER PROCEDURE `NewProc`()
    DETERMINISTIC
BEGIN
 #Routine body goes here...
END;;

第二种是信任子程序的创建者，禁止创建、修改子程序时对SUPER权限的要求，设置log_bin_trust_routine_creators全局系统变量为1。设置方法有三种:
1.在客户端上执行SET GLOBAL log_bin_trust_function_creators = 1;
2.MySQL启动时，加上--log-bin-trust-function-creators选贤，参数设置为1
3.在MySQL配置文件my.ini或my.cnf中的段上加log-bin-trust-function-creators=1

7 . Mysql数据库的使用总结之ERROR 1146 (42S02) 
   修改 my.cnf 中 区分大小：
   lower_case_table_names = 1



××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××