MySQL for linux安装详解

 
MySQL for linux安装详解(mysql-5.1.40-linux-i686-glibc23.tar.gz安装笔记)
安装源代码版本的MySQL
1.首先添加mysql用户组
shell> groupadd mysql
 
2.添加mysql用户,并指定到mysql用户组
shell> useradd -g mysql mysql
 
3.解压缩mysql-version.tar.gz
shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -
4.安装mysql
shell> cd mysql-VERSION
shell> ./configure --prefix=/usr/local/mysql --with-charset=gbk --with-extra-charsets=armscii8,ascii,big5,cp1250,cp1251,cp1256,cp1257,cp850,cp852,cp866,cp932,dec8,eucjpms,euckr,gb2312,gbk,geostd8,greek,hebrew,hp8,keybcs2,koi8r,koi8u,latin1,latin2,latin5,latin7,macce,macroman,sjis,swe7,tis620,ucs2,ujis,utf8 --with-plugins=innodb_plugin
shell> make
shell> make install
 
5.复制配置文件
shell> cp support-files/my-medium.cnf /etc/my.cnf
 
6.执行mysql系统数据库初始化脚本
shell> cd /usr/local/mysql
shell> bin/mysql_install_db --user=mysql
 
7.设定mysql安装目录权限,设置owner为mysql
shell> chown -R mysql var
shell> chgrp -R mysql .
 
8.启动mysql应用
shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &
 
9.设置root密码(数据库的DBA)
shell> bin/mysqladmin -u root password ‘123456’
 
10.登录mysql
shell> bin/mysql -u root -p
Enter password:
登录成功会看到:
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 229
Server version: 5.1.40-log MySQL Community Server (GPL)
 
Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the current input statement.
 
mysql>
 
这时mysql已经装好了,可以查看数据库了,但在正式使用数据库开发与部署的时候还需要做一些工作:


1.设定配置文件my.cnf

    按照需求copy my-***.cnf到/etc/my.cnf

2.修改默认字符集utf8

    (1).[client]下加入default-character-set=utf8
    (2).[mysqld]下加入default-character-set=utf8
#不改动存储引擎的话,3、4步可以略过
3.启动InnoDB引擎的方法如下:
    1)关闭mysql的服务
    2)修改my.ini
        将default-storage-engine=INNODB前的注释(#)去掉
        将skip-innodb这行注释(加上#)

4.配置innodb参数 
     1).找到# Uncomment the following if you are using InnoDB tables
        去掉innodb_*下的所有# 

     2).如果安装mysql的目录不是默认的,则需要修改
        # mysql 默认安装目录为 /usr/local/mysql/
        # mysql 默认表空间目录安装目录为 /usr/local/mysql/var/

        innodb_data_home_dir=/usr/local/database/mysql/var/
        innodb_log_group_home_dir=/usr/local/database/mysql/var/
     3).保存后重启mysql服务。

5.设置系统服务

    让linux启动的时候就启动mysql服务
shell> cd /usr/local/mysql/
shell> cp support-files/mysql.server /etc/init.d/mysql
shell> chmod 777 /etc/init.d/mysql
shell> chkconfig --add mysql
shell> chkconfig --level 35 mysql on
 
6.重启MySQL服务
shell> service mysql restart

备注:
Add a login user and group for ‘mysqld’ to run as:为‘mysqld’增添一个登陆用户和组

shell> groupadd mysql
shell> useradd -g mysql mysql

Configure the release and compile everything:配置和编译

shell> ./configure --prefix=/usr/local/mysql
--prefix后面指示了默认安装路径
shell> make
如果还想知道更详细的configure命令,请查阅manual for configure

If you want to set up an option file, use one of those present in
the ‘support-files’ directory as a template. For example:如果你想安装选项文件,使用当前存在的‘support-files’ 文件夹下的作为模板,例如:

shell> cp support-files/my-medium.cnf /etc/my.cnf

If you haven`t installed MySQL before, you must create the MySQL
grant tables:如果你以前没有安装过MySQL,你必须创建一个MySQL准许的表

shell> bin/mysql_install_db --user=mysql

Change the ownership of program binaries to ‘root’ and ownership
of the data directory to the user that you will run ‘mysqld’ as.
Assuming that you are located in the installation directory
(‘/usr/local/mysql’), the commands look like this:将程序的所有权限给‘root’ ,并且把数据目录的所有权给可以运行‘mysqld’的用户。假设MySQL的安装目录是(‘/usr/local/mysql’),命令如下所示:

shell> chown -R mysql var
shell> chgrp -R mysql .

The first command changes the owner attribute of the files to the ‘root’ user. 第一行命令把文件拥有权给‘root’。The second changes the owner attribute of the data directory to the ‘mysql’ user. 第二行把数据目录拥护权给‘mysql’用户。The third changes the group attribute to the ‘mysql’ group.第三行把组的权限给‘mysql’组。

After everything has been installed, you should initialize and test your distribution using this command:万事具备后,你就可以按照下面的命令测试并运行你的MySQL了:

shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &

 
注:文件中的单引号全应该是英文状态下输入的,但是发布不了,我只好改成中文状态下输入的单引号了。
 
mysql 远程连接
1.以root用户登录mysql后,执行如下命令:
grant all privileges on *.* to root@’允许登录的远程机器ip’
identified by ‘密码’

其中,*.*表示该主机中所有数据库的所有表。(数据库.表)
“给某IP地址上登录的root用户授予访问所有数据库中的所有表的所有权限”
 
如果想让所有主机都可以远程连接,则执行完步骤1后
把user表里刚加的那一条的hostname改成%
这样就可以了。
 
如果数据库里出现乱码,则把client环境中的LANG改成GBK2312就可以了。
MYSQL ERROR 1045 (28000): Access denied for user (using password: YES)问题的解决

第一种方法: 推荐
错误描述: Mysql中添加用户之后可能出现登录时提示ERROR 1045 (28000): Access denied for user的错误.
原因分析: 在mysql.user表中可能出现user为空的记录,如:
mysql> select host,user from user;
+------------------+------+
| host | user |
+------------------+------+
| % | test |
| localhost | |
| localhost | root |
+------------------+------+
3 rows in set (0.00 sec)
解决 办法: 删除这些为空的用户或者更新为其他用户名
删除user.user中值为NULL的,或更新NULL为test
1)delete from user where user is NULL
2)update user set user='test' where user is NULL
意外的情况: 如果上述方法没有效果,依然出现空用户,则可以利用图形化用户client删除.
第二种方法:linux下
开场白:解决LINUX问题是一种乐趣,当然,能遇到问题就是上天赐的享受幸福的机会。
这次使用的是Mandriva2008spring。
因为要搞一个项目,所以需要安装MySql,以往安装MySql都是非常顺利的,尤其MySql提供的rmp包,只需双击下就可以搞定~但不知道什么时候,MYSQL ERROR 1045 (28000): Access denied for user (using password: YES),这个拒绝访问问题变得非常广泛。
百度了一下,没有现成的解决方法,唯有找出其问题所在了。
解决问题思路:
第一步,先使用跳过受权表访问,命令如下:mysqld_safe --user=mysql --skip-grant-tables --skip-networking & (当然,在这之前,先停止mysql服务的运行)。
第二步,mysql -uroot mysql 登录mysql。
第三步,访问mysql数据库下的user表。在我的机器上,mysql> select * from user; 得到的,竟然是
Empty set (0.00 sec)。这说明了,我的mysql没有任何可以访问的用户。知道了这问题所在,解决起来就简单了。
第四步,mysql> INSERT INTO user(host, user, password, select_priv, insert_priv, update_priv) VALUES ('localhost', 'username', PASSWORD(‘yourpassword'), 'Y', 'Y','Y');
Query OK, 1 row affected, 3 warnings (0.00 sec)
返回成功,没问题。嘿嘿~~~就这么简单。
第五步,测试,再重启下mysql服务,正常登录,成功!!!
提示:mysql系统中的mysql数据库,存储的是系统数据,像这里的user表存储的是用户信息及其访问权限,还有其他,例如你要新建一个数据库mydb,这数据库有用户me管理的话,mysql数据库里面的db表就会存储相关信息。废话步多说了。
下面是windows 的解决方法:
但如果我们用虚拟主机管理系统开启的用户,而且用户数比较多的时候,好像也不是好办法。
我使用重新安装了mysql,然后进入虚拟主机,逐个删除,重新开数据库,操作之前一定要备份好原来的data目录,最后覆盖下空间数据库就可以了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值