教程集 www.jiaochengji.com
教程集 >  数据库  >  mysql  >  正文 linux下mysql数据库安装与配置步骤

linux下mysql数据库安装与配置步骤

发布时间:2016-03-15   编辑:jiaochengji.com
本文分享下,在linux下安装与配置mysql数据库的几大步骤,学习下mysql数据库的安装配置方法,有需要的朋友作个参考。

一,首先,查看LINUX的版本
 

复制代码 代码示例:
[root@jbxue mysql]# lsb_release -a
LSB Version: :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarch Distributor ID: RedHatEnterpriseServer Description: Red Hat Enterprise Linux Server release 5.2 (Tikanga) Release: 5.2 Codename: Tikanga
 

然后,去mysql官网http://dev.mysql.com/downloads/mysql/下载MySQL的相应版本的安装文件.
一般情况下,下载两个和linux系统相对应的mysql安装文件即可。

分别是server和client版本。
 

复制代码 代码示例:
http://downloads.mysql.com/archives.php?p=mysql-5.1&v=5.1.58
RedHat Enterprise Linux 5 RPM (AMD64, Client programs) (4 Jul 2011, 7.2M)
RedHat Enterprise Linux 5 RPM (AMD64, Server) (4 Jul 2011, 20.3M)
 

具体文件见二。
 
二,将下载后的对应的安装文件放到linux下自定义的一个新建的文件夹mysql下。
使用命令安装相应的rpm文件。

在mysql文件路径下,输入如下命令即可。

首先,安装服务器端 :
 

复制代码 代码示例:
[root@jbxue mysql]#rpm -ivh MySQL-server-community-5.1.58-1.rhel5.x86_64.rpm

其次,安装客户端 :
 

复制代码 代码示例:
[root@jbxue mysql]#rpm -ivh MySQL-client-community-5.1.58-1.rhel5.x86_64.rpm
 

例如:
 

复制代码 代码示例:
[root@jbxue software]# rpm -ivh MySQL-server-community-5.1.58-1.rhel5.x86_64.rpm 
Preparing...                ########################################### [100%] 
   1:MySQL-server-community ########################################### [100%] 
 
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! 
To do so, start the server, then issue the following commands: 
 
/usr/bin/mysqladmin -u root password 'new-password' 
/usr/bin/mysqladmin -u root -h  password 'new-password' 
 
Alternatively you can run: 
/usr/bin/mysql_secure_installation 
 
which will also give you the option of removing the test 
databases and anonymous user created by default.  This is 
strongly recommended for production servers. 
 
See the manual for more instructions. 
 
Please report any problems with the /usr/bin/mysqlbug script! 
 
Starting MySQL..[è·?¨] 
Giving mysqld 2 seconds to start 
[root@jbxue software]# rpm -ivh MySQL-client-community-5.1.58-1.rhel5.x86_64.rpm 
Preparing...                ########################################### [100%] 
   1:MySQL-client-community ########################################### [100%] 
[root@jbxue software]# 
 

三,安装完成后,
mysql安装目录可能在:/usr/bin/mysql 
mysql启动文件可能在: /etc/rc.d/init.d/mysqld
使用whereis mysql命令来查找它安装的路径
使用命令 rpm -qal | grep mysql 确定linux下已安装MYSQL的安装路径。
例如:
 

复制代码 代码示例:
[root@jbxue mysql]# rpm -qal | grep mysql
 
//使用如下命令查看系统是否已经安装mysql
[root@jbxue mysql]# rpm –qa | grep mysql
 

或键入命令:
 

复制代码 代码示例:
[root@jbxue mysql]$ netstat -nat
tcp 0 0 127.0.0.1:3306 127.0.0.1:33648 ESTABLISHED tcp 0 0 127.0.0.1:3306 127.0.0.1:33649 ESTABLISHED
 

出现以上内容。
或直接敲入命令mysql+回车
 

复制代码 代码示例:
[root@jbxue ~]$mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5136 Server version: 5.1.58-community MySQL Community Server (GPL) Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
 

即表示linux下mysql安装成功

第二部发,对已安装完成的mysql,进行相应的配置

MySQL默认没有密码,安装完毕增加密码的重要性是不言而喻的。
1、命令
usr/bin/mysqladmin -u root password 'new-password'
格式:mysqladmin -u用户名 -p旧密码 password 新密码
例:给root加个密码ysong。
键入以下命令 :
[root@jbxue ~]$ /usr/bin/mysqladmin -u root password ysong
注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。
 
此时,在敲入,即可访问mysql
 

复制代码 代码示例:
[root@jbxue ~]$ mysql -uroot -pysong
 
[ysong@IDC ~]$mysql -uroot -pysong Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5159 Server version: 5.1.58-community MySQL Community Server (GPL) Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
 

1、用命令启动mysql
MySQL安装完成后启动文件mysql在/etc/init.d目录下,在需要启动时运行下面命令即可。
[root@jbxue ~]$sudo  /etc/init.d/mysql start
注:sudo运行,不然可能会报错,权限原因;
 

复制代码 代码示例:
[root@jbxue ~]$  /etc/init.d/mysql start
Starting MySQL.Manager of pid-file quit without updating file.[失败]
 

2、用命令停止mysql
 

复制代码 代码示例:
[root@jbxue ~]$ /usr/bin/mysqladmin -u root -pysong shutdown
 

1:创建用户:
 

复制代码 代码示例:
CREATE USER ' pig'@'% ' IDENTIFIED BY 'ysong';
[root@jbxue ~]$ mysql -uysong -psong
[root@jbxue ~]$ mysql -uroot -pysong
grant all privileges on e6mall.* to ysong@'%'
grant select,insert,alter,drop on e6mall.* to ysong@"%" identified by "song";
GRANT ALL PRIVILEGES ON e6mall.* TO ysong@"%" IDENTIFIED BY "song";
use mysql;
select user,password from user;
delete from user where user is NULL
update user set password='ysong' where user is 'ysong';

2:授权:
 

复制代码 代码示例:
use mysql 
update user set password=password('mysql') where user='root';
update user set password=password('ysong') where user='ysong';
flush privileges;
 

最后,创建数据库,导入数据库sql文件。
 

复制代码 代码示例:
mysql -uroot -pysong
create database e6mall;
mysql -uroot -pysong e6mall < /opt/mysql/e6mall.sql;

至此,就完成了linux下mysql数据库的安装与配置,希望对大家有所帮助。

您可能感兴趣的文章:
Linux Apache Mysql PHP典型配置
yum方式安装MySQL并设置密码
Ubuntu下安装搭建MySQL环境步骤介绍
linux下mysql的安装与配置过程详解
查看mysql编码方式 mysql数据库编码查看方法
Ubuntu 11.10安装MySQL 5.5.x版本
linux下mysql数据库安装与配置步骤
mysql字符编码查看修改实例
Linux下指定数据库数据配置主主同步的实例
linux下指定数据库服务器主从同步的实例

关键词: mysql安装   
[关闭]
~ ~