重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

mysql数据库的安装之二二进制安装

#二进制安装MySQL,直接解压初始化数据库就可以了

创新互联专业为企业提供荣成网站建设、荣成做网站、荣成网站设计、荣成网站制作等企业网站建设、网页设计与制作、荣成企业网站模板建站服务,十年荣成做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

1.创建用户和组

[root@Lnmp tools]#useradd mysql -s /sbin/nologin/ -M

2.解压安装包

[root@Lnmp tools]#tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz 

[root@Lnmp tools]#mv mysql-5.5.32-linux2.6-x86_64 mysql

[root@Lnmp tools]#mv mysql /application/ 

#独立安装数据库到此结束。

[root@Lnmp tools]# mkdir -p /application/mysql/data/

[root@Lnmp tools]#chown -R mysql.mysql /application/mysql/data

3.初始化数据库

[root@Lnmp tools]# cd /application/mysql/

[root@Lnmp mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/application/mysql/ --datadir=/application/mysql/data/

WARNING: The host 'Lnmp' could not be looked up with resolveip.

This probably means that your libc libraries are not 100 % compatible

with this binary MySQL version. The MySQL daemon, mysqld, should work

normally with the exception that host name resolving will not work.

This means that you should use IP addresses instead of hostnames

when specifying MySQL privileges !

Installing MySQL system tables...

OK

Filling help tables...

OK

[root@Lnmp mysql]# \cp support-files/mysql.server /etc/init.d/mysqld

[root@Lnmp mysql]#cp support-files/my-small.cnf /etc/my.cnf  #指定配置文件

#如果不指定则,启动时出现:

ERROR 2002 (HY000):Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock/(2)

4.启动Mysql:

[root@Lnmp mysql]# /etc/init.d/mysqld start 

/etc/init.d/mysqld: line 276: cd: /usr/local/mysql: No such file or directory

Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)

如果不成功则修改下面:

[root@Lnmp mysql]# vi /etc/init.d/mysqld  +46

basedir=/application/mysql

datadir=/application/mysql/data

[root@Lnmp mysql]# /etc/init.d/mysqld start

Starting MySQL.. SUCCESS! 

#登录

#mysql

出现下面错误:

#-bash:mysql:command not found

mysql 对应的路径不在path目录下面

使用全路径进入mysql:

/application/mysql/bin/mysql

或者在文件最后加上:

vi /etc/profile

PATH="/application/mysql/bin/:$PATH"

#. /etc/profile   #使之生效

mysql>

#设置密码,不要在mysql>  下面设置密码,在#后面设置密码

/application/mysql/bin/mysqladmin -u  root password 'passwd123'

#重新登录

mysql -u root -p

passwd123

5.数据优化:

select version();         #查看数据库版本

select user();            #查看当前的用户

mysql> show databases;    #查看数据库

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

+--------------------+

mysql>drop database test; #安全设置,删除没有用的数据库

#最终优化为:

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

+--------------------+

mysql> select user,host from mysql.user;  #查询表中的用户

+------+-----------+

| user | host      |

+------+-----------+

| root | 127.0.0.1 |

| root | ::1       |

|      | Lnmp      |

| root | Lnmp      |

|      | localhost |

| root | localhost |

+------+-----------+

mysql>delete from mysql.user where(host="Lnmp");

mysql>delete from mysql.user where(host="::1");

mysql> drop user ""@localhost;

#最终优化为:

mysql> select user,host from mysql.user;

+------+-----------+

| user | host      |

+------+-----------+

| root | 127.0.0.1 |

| root | localhost |

+------+-----------+

最后:

flush privileges;


新闻标题:mysql数据库的安装之二二进制安装
文章分享:http://cqcxhl.cn/article/jcoipo.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP