“天街小雨润如酥,草色遥看近却无。最是一年春好处,绝胜烟柳满皇都。”读一首古诗,心情也随之平静下来

发布新日志

  • Linux下oracle10g的安装与配置及相关问题解决方案(七)

    2010-12-30 16:56:35Top 1 Digest 1

    第四部分 Oracle的使用

    4.1 配置oracle的环境变量

    [oracle@localhost ~]$export ORACLE_BASE=/home/mytools/programs/oracle/u01/app/oracle
    [oracle@localhost ~]$export ORACLE_SID=ORCL
    [oracle@localhost ~]$export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
    [oracle@localhost ~]$export PATH=$PATH:$ORACLE_HOME/bin

    4.2 启动和关闭Oracle数据库

    [oracle@localhost ~]$ su oracle

    [oracle@localhost ~]$ sqlplus system/system as sysdba

     

    SQL*Plus: Release 10.2.0.1.0 - Production on Wed Dec 29 23:45:16 2010

     

    Copyright (c) 1982, 2005, Oracle.  All rights reserved.

     

     

    Connected to:

    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

    With the Partitioning, OLAP and Data Mining options

    oracle已经启动,可正常访问,或者采用如下方式启动)

    $ sqlplus
     
    SQL*Plus:Release 10.1.0.2.0 - Production on Sun Jun 13 22:27:48 2004
     
    Copyright (c) 1982, 2004, Oracle.All rights reserved.
     
    Enter user-name:/ as sysdba
    Connected to an idle instance.
     
    SQL> startup 启动oracle数据库实例

     

    SQL> shutdown immediate 关闭oracle数据库实例
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    SQL> exit

     

    4.3 启动和停止 Oracle Enterprise Manager 数据库控制

    $ emctl start dbconsole
    $ emctl stop dbconsole
    (说明:必须启动dbconsole才能访问http://localhost.localdomain:1158/em

    4.4 启动和停止 iSQL*Plus

    $ isqlplusctl start
    $ isqlplusctl stop

    (说明:只有启动了isqlplusctl才可以使用url的形式访问,同时如果linux系统中iptables是开启状态的话,需要将5560的端口添加到开放列表中方可在其他机器上访问

    http://localhost.localdomain:5560/isqlplus

    4.5 启动和停止监听器

    监听器接受客户端的连接请求,并在验证证书后创建数据库连接。要使用 OEM iSQL*Plus,必须先启动监听器。

    $ lsnrctl start
    $ lsnrctl stop

     

    第五部分 Oracle的卸载

    5.1  运行 $ORACLE_HOME/bin/localconfig delete

    5.2  rm -rf $ORACLE_BASE/*

    5.3  rm -f /etc/oraInst.loc /etc/oratab

    5.4  rm -rf /etc/oracle

    5.5  rm -f /etc/inittab.cssd

    5.6  rm -f /usr/local/bin/coraenv /usr/local/bin/dbhome /usr/local/bin/oraenv

    5.7  删除oracle用户和组。

     

    参考文档:http://www.oracle.com/technology/global/cn/pub/articles/smiley_10gdb_install.html

  • Linux下oracle10g的安装与配置及相关问题解决方案(六)

    2010-12-30 16:54:26Top 1 Digest 1

    Step4 执行安装

    安装过程中报错:Error in invoking target 'all_no_orcl ihsodbc' of makefile

    '/home/mytools/programs/oracle/u01/app/oracle/product/10.2.0/db_1/rdbms/lib/ins_rdbms.mk'. See

    '/home/mytools/programs/oracle/u01/app/oracle/oraInventory/logs/installActions2010-12-29_06-37-05PM.log' for details.

    解决方案:查看installActions2010-12-29_06-37-05PM.log文件,发现/usr/lib/libstdc++.so.5: No such file or directory,需要安装该libstdc++.so.5

    [oracle@localhost ~]$ tail -100  /home/mytools/programs/oracle/u01/app/oracle/oraInventory/logs/installActions2010-12-29_06-37-05PM.log

    INFO: gcc:

    INFO: /usr/lib/libstdc++.so.5: No such file or directory

    INFO: /home/mytools/programs/oracle/u01/app/oracle/product/10.2.0/db_1/bin/genorasdksh: Failed to link liborasdkbase.so.10.2

    INFO: make:

    INFO: *** [liborasdkbase] Error 1

    (解决方案:进入Linux安装盘中找到compat-libstdc++-33-3.2-61.i386.rpm文件,安装,回到oracle安装界面retrycontinue)

    Step5 手动执行两个sh文件

    [oracle@localhost ~]$ su root (根据提示这两个sh文件需要root用户执行,完成后点ok

    Password:

    [root@localhost oracle]# sh /home/mytools/programs/oracle/u01/app/oracle/oraInventory/orainstRoot.sh

    [root@localhost oracle]# sh /home/mytools/programs/oracle/u01/app/oracle/product/10.2.0/db_1/root.sh

     

    Setp6 安装结束

    记录下上图中的链接,以便于通过url访问,需要注意的是,使用url访问,必须把dababaselisteneriSQL*PlusOEMOrcle Enterprise Manager)全部启动

    The following J2EE Applications have been deployed and are accessible at the URLs listed below.

     

    iSQL*Plus URL:

    http://localhost.localdomain:5560/isqlplus

     

    iSQL*Plus DBA URL:

    http://localhost.localdomain:5560/isqlplus/dba

     

    Enterprise Manager 10g Database Control URL:

    http://localhost.localdomain:1158/em

    至此Linux下的oracle安装就结束了

     

  • Linux下oracle10g的安装与配置及相关问题解决方案(五)

    2010-12-30 16:52:59Top 1 Digest 1

    Step3 环境自检验证

    Oracle对系统环境的验证,通过会显示passed,不通过的会给出warningfailed的提示信息,可以把下面信息显示区域的错误描述拷贝出来检查

    本机在检查过程中出现如下错误(此处只截取了失败的错误提示)

    错误一

    Checking kernel parameters

    Checking for rmem_default=262144; found rmem_default=109568.    Failed <<<<

    Checking for rmem_max=262144; found rmem_max=131071.    Failed <<<<

    Checking for wmem_default=262144; found wmem_default=109568.    Failed <<<<

    Checking for wmem_max=262144; found wmem_max=131071.    Failed <<<<

    Check complete. The overall result of this check is: Failed <<<<

    Problem: The kernel parameters do not meet the minimum requirements (see above).

    Recommendation: Perform. operating system specific instructions to update the kernel parameters. (此处提示当前系统内核参数的配置跟最小配置要求不一致,需要调整配置参数)

     

    [root@localhost ~]# cat >> /etc/sysctl.conf <<EOF

    >net.core.rmem_default=262144

    >net.core.rmem_max=262144

    >net.core.wmem_default=262144

    >net.core.wmem_max=262144

    >EOF

     

    [root@localhost ~]# /sbin/sysctl –p

    =======================================================================

    错误二

    Checking physical memory requirements ...

    Expected result: 922MB

    Actual Result: 500MB

    Check complete. The overall result of this check is: Failed <<<<

    Problem: The system does not have sufficient physical memory to perform. the install.

    Recommendation: Increase the amount of physical memory available to your system before continuing with the installation.(物理内存的大小不足,期望992MB,实际只有500MB

    解决方案,因为是在Vmware虚拟机上安装的Linux,所以调整Vmware的内存配置为1G,此时又出现新问题

     

    错误三

    Checking available swap space requirements ...

    Expected result: 1512MB

    Actual Result: 1019MB

    Check complete. The overall result of this check is: Failed <<<<

    Problem: The system does not have the required swap space.

    Recommendation: Make more swap space available to perform. the install.

    从此处来看,急需解决的是如何调整swap空间,因为当然Vmware的内存为1G,按常规看Swap交换空间应该为2G,下面就是解决swap交换空间的问题

     

    第一步:使用free -m查看目前swap的交换空间情况,1019M,也可以使用grep SwapTotal  /proc/meminfo查看

     

    [root@localhost swapimage]# free -m

                 total       used       free     shared    buffers     cached

    Mem:          1010        995         15          0          1        847

    -/+ buffers/cache:        145        865

    Swap:         1019          0       1019

     

    df –h查看磁盘空间的使用情况

    [root@localhost ~]# df -h

    Filesystem            Size  Used Avail Use% Mounted on

    /dev/sda2             3.8G  3.1G  572M  85% /

    /dev/sda3              15G  1.7G   13G  13% /home

    /dev/sda1              46M   11M   33M  25% /boot

    tmpfs                 506M     0  506M   0% /dev/shm

     

    第二步:确保系统中有足够的空间用来做swap交换空间,经过df –h查看,只有/home下面还有13G的空间是比较大的,所以我这边准备在/home/swapimage开辟swap交换区

    [root@localhost home]# mkdir swapimage /home目录下创建swapimage文件夹

    [root@localhost home]# cd swapimage/   进入swapimage文件夹

    [root@localhost swapimage]# dd if=/dev/zero f=/home/swapimage/swap bs=1024 count=1024000 添加交换文件并设置大小为1G

    1024000+0 records in

    1024000+0 records out

    1048576000 bytes (1.0 GB) copied, 16.2007 seconds, 64.7 MB/s

     

    再次用df –h查看磁盘空间的使用情况,/home的可以大小已经由13G变成12G了,也就是说通过上面的dd操作,我们已经成功的分配了1Gswap交换空间

    [root@localhost swapimage]# df -h

    Filesystem            Size  Used Avail Use% Mounted on

    /dev/sda2             3.8G  3.1G  572M  85% /

    /dev/sda3              15G  2.7G   12G  20% /home

    /dev/sda1              46M   11M   33M  25% /boot

    tmpfs                 506M     0  506M   0% /dev/shm

     

    第三步:使用mkswap命令,创建(或设置)交换空间

    [root@localhost swapimage]# mkswap /home/swapimage/swap

    Setting up swapspace version 1, size = 1048571 kB

     

    第四步:使用swapon命令,启用新增的1G交换空间

    [root@localhost swapimage]# swapon /home/swapimage/swap

    使用free –m确认新增的swap交换空间已生效,2019

    [root@localhost swapimage]# free -m

                 total       used       free     shared    buffers     cached

    Mem:          1010        997         13          0          2        848

    -/+ buffers/cache:        146        864

    Swap:         2019          0       2019

     

    第五步:修改/etc/fstab文件,使新增的1G交换空间在系统重启后自动生效

    [root@localhost swapimage]# vi /etc/fstab

    /home/swapimage/swap   swap   swap   defaults   0 0

    =======================================================================

    Checking Network Configuration requirements ...

    Check complete. The overall result of this check is: Not executed <<<<

    Recommendation: Oracle supports installations on systems with DHCP-assigned public IP addresses.  However, the primary network interface on the system should be configured with a static IP address in order for the Oracle Software to function properly.  See the Installation Guide for more details on installing the software on systems configured with DHCP.(推荐系统采用静态的IP设置)

     

    解决方案:切换到root用户,进行静态IP地址的配置

    [oracle@localhost database]$ vi /etc/sysconfig/network-scripts/ifcfg-eth0

    # Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]

    DEVICE=eth0

    #BOOTPROTO=dhcp

    BOOTPROTO=static

    IPADDR=192.168.1.289

    NETMASK=255.255.255.0

    GATEWAY=192.168.1.1

    #HWADDR=00:0c:29:c9:31:a9

    ONBOOT=yes

    TYPE=Ethernet

     

    重启使IP地址生效

    /sbin/ifdown eth0

    /sbin/ifup eth0

     

    配置DNS解析

    Echo “nameserver 218.135.1.26”>> /etc/resolv.conf

     

    通知网关更新信息

    /etc/init.d/network restart

     

    设置好静态IP地址后retry,还是Not executed,搜索到资料讲需要修改/etc/hosts文件,将127.0.0.1修改为192.168.1.289(也就是设置的静态IP地址)

    [oracle@localhost database]$ su root

    Password:

    [root@localhost database]# vi /etc/hosts

    修改后retry检查,通过passed

    =======================================================================

    该步骤结束后,系统会提示某些检查没有通过,是否继续并手动配置

     

  • Linux下oracle10g的安装与配置及相关问题解决方案(四)

    2010-12-30 16:50:41Top 1 Digest 1

    第三部分 安装Oracle

    4.1 设置环境变量ORACLE_SID

    使用 oracle 帐户登录。

    指定数据库名称 (ORACLE_SID)。该名称通常不多于五个字符。此处安装使用ORCL

    [oracle@localhost ~]$ vi .bash_profile

    ORACLE_SID=ORCL

    export PATH ORACLE_BASE ORACLE_SID

    4.2 开始安装

    [oracle@localhost database]$cd /home/mytools/oracle/database 进入oracle的安装文件目录

    [oracle@localhost database]$ ./runInstaller启动oracle的安装界面开始执行安装

    Step1 基本信息设置

    设置oracleHome路径:

    /home/mytools/programs/oracle/u01/app/oracle/product/10.2.0/db_1

    UNIX DBA GROUP设置为dba

    设置SYSSYSTEMSYSMAN,和DBSNMP账户的密码

    Step2 详细目录设置

    设置详细目录:/home/mytools/programs/oracle/u01/app/oracle/oraInventory

    操作系统的群组设置为oinstall

  • Linux下oracle10g的安装与配置及相关问题解决方案(三)

    2010-12-30 16:49:42Top 1 Digest 1

    3.1 配置 Linux 内核参数

    Oracle 数据库 10g 需要以下所示的内核参数设置。下面给出的是最小配置,如果当前系统使用的值较大,则不要更改它。

    kernel.shmall = 2097152
    kernel.shmmax = 2147483648
    kernel.shmmni = 4096
    kernel.sem = 250 32000 100 128
    fs.file-max = 65536
    net.ipv4.ip_local_port_range = 1024 65000

     

    执行/sbin/sysctl –p命令查看本机的linux内核配置

    [root@localhost ~]# /sbin/sysctl –p

    net.ipv4.ip_forward = 0

    net.ipv4.conf.default.rp_filter = 1

    net.ipv4.conf.default.accept_source_route = 0

    kernel.sysrq = 0

    kernel.core_uses_pid = 1

    net.ipv4.tcp_syncookies = 1

    kernel.msgmnb = 65536

    kernel.msgmax = 65536

    kernel.shmmax = 4294967295

    kernel.shmall = 268435456

     

    跟上面的最低配置比较还有好几项没有配置,所以还要执行命令进行配置

    [root@localhost ~]# cat >> /etc/sysctl.conf <<EOF

    > kernel.shmmni = 4096

    > kernel.sem = 250 32000 100 128

    > fs.file-max = 65536

    > net.ipv4.ip_local_port_range = 1024 65000

    > EOF

     

    验证配置还可以使用如下命令

    /sbin/sysctl -a | grep shm
    /sbin/sysctl -a | grep sem
    /sbin/sysctl -a | grep file-max
    /sbin/sysctl -a | grep ip_local_port_range

     

    再次执行/sbin/sysctl –p命令查看本机的linux内核配置,所需配置都已经有了,/sbin/sysctl -p命令主要起到激活更改的目的

    [root@localhost ~]# sysctl -p

    net.ipv4.ip_forward = 0

    net.ipv4.conf.default.rp_filter = 1

    net.ipv4.conf.default.accept_source_route = 0

    kernel.sysrq = 0

    kernel.core_uses_pid = 1

    net.ipv4.tcp_syncookies = 1

    kernel.msgmnb = 65536

    kernel.msgmax = 65536

    kernel.shmmax = 4294967295

    kernel.shmall = 268435456

    kernel.shmmni = 4096

    kernel.sem = 250 32000 100 128

    fs.file-max = 65536

    net.ipv4.ip_local_port_range = 1024 65000

     

    对于 SLES 8SUSE Linux Enterprise 8),完成上述步骤后还需要运行以下命令

    /sbin/chkconfig boot.sysctl on
     

    3.2 oracle 用户设置 Shell 限制

    Oracle 建议对每个 Linux 帐户可以使用的进程数和打开的文件数设置限制。要进行这些更改,以 root 用户的身份执行下列命令:

    [root@localhost ~]# cat >> /etc/security/limits.conf <<EOF /etc/security/limits.conf追加信息直到输入EOF结束

    > oracle               soft    nproc   2047

    > oracle               hard    nproc   16384

    > oracle               soft    nofile  1024

    > oracle               hard    nofile  65536

    > EOF

    [root@localhost ~]# cat >> /etc/pam.d/login <<EOF

    > session required /lib/security/pam_limits.so

    > EOF

    3.3 设置oracle 用户的环境变量

    要使用 Oracle 产品,需要设置几个环境变量。对于数据库服务器,建议设置以下环境变量:

    ORACLE_BASE
    ORACLE_HOME
    ORACLE_SID
    PATH

    如果您在同一服务器上安装了多个 Oracle 产品或数据库,则 ORACLE_HOMEORACLE_SID PATH 变量可能会更改。ORACLE_BASE 变量不应更改,并可以在需要时在您的登录配置文件中设置它。Oracle 提供了一个称作 oraenv 的实用程序来设置其他变量。

    Linux环境变量设置文件)

    /etc/profile  (全局用户,应用于所有的Shell

    /$HOME/.profile(当前用户,应用于所有的Shell

    /etc/bash_bashrc(全局用户,应用于Bash Shell

    ~/.bashrc (局部当前,应用于Bash Sell

    oracle身份登录配置oracle用户的环境变量

    [oracle@localhost ~]$ ls –a (显示所有的文件,包含隐藏文件)

    .              .bashrc   .gconfd          .gtkrc-1.2-gnome2  .redhat

    ..             Desktop   .gnome           .ICEauthority      .Trash

    .bash_history  .dmrc     .gnome2          .metacity          .xsession-errors

    .bash_logout   .eggcups  .gnome2_private  .mozilla

    .bash_profile  .gconf    .gstreamer-0.10  .nautilus

     

    [oracle@localhost ~]$ vi .bash_profile

    ORACLE_BASE=/home/mytools/programs/oracle/u01/app/oracle

    export PATH ORACLE_BASE

  • Linux下oracle10g的安装与配置及相关问题解决方案(二)

    2010-12-30 16:48:48Top 1 Digest 1

    第二部分 针对Oracle配置Linux

    3.1 检查Linux系统空间

    要验证系统是否满足 Oracle 10g 数据库的最低要求,以 root 用户身份登录并运行以下命令。

    运行以下命令查看可用 RAM 和交换空间大小:

    [root@localhost oracle]# grep MemTotal /proc/meminfo

    MemTotal:       515444 kB

    [root@localhost oracle]# grep SwapTotal /proc/meminfo

    SwapTotal:     1044184 kB

    所需最小 RAM 512MB,而所需最小交换空间为 1GB。对于 RAM 小于或等于 2GB 的系统,交换空间应为 RAM 数量的两倍;对于 RAM 大于 2GB 的系统,交换空间应为 RAM 数量的一到两倍。

    -------------------------------------------------------------------------------Oracle 10g 软件还需要 2.5GB 的可用磁盘空间,而数据库则另需 1.2GB 的可用磁盘空间。/tmp 目录至少需要 400MB 的可用空间。要检查系统上的可用磁盘空间,运行以下命令:

    [root@localhost oracle]# df -h

    Filesystem            Size  Used Avail Use% Mounted on

    /dev/sda2             3.8G  3.1G  573M  85% /

    /dev/sda3              15G  1.1G   13G   8% /home

    /dev/sda1              46M   11M   33M  25% /boot

    tmpfs                 252M     0  252M   0% /dev/shm

     

    从结果看,/tmp 目录没有自己的文件系统,它是根文件系统的一部分。根文件系统可用空间为还有573M,够/tmp的最低要求,这样就需要把Oracle10g和所需的数据库空间共5.2 GB分配到/home目录下,除了满足安装 (2.5 + 1.2 + 0.4 = 4.1GB) 外还有很大的富余。

     

    3.2 创建 Oracle 组和用户帐户

    接下来,创建用于安装和维护 Oracle 10g 软件的 Linux 组和用户帐户。用户帐户: oracle,组:oinstall dba。以 root 用户身份执行以下命令:

    [root@localhost oracle]# groupadd oinstall 创建组oinstall

    [root@localhost oracle]# groupadd dba 创建组dba

    [root@localhost oracle]# useradd -m -g oinstall -G dba oracle 创建用户oracle并分配群组

    [root@localhost oracle]# id oracle 查看用户oracle的信息

    uid=503(oracle) gid=503(oinstall) groups=503(oinstall),504(dba) context=root:system_r:unconfined_t:SystemLow-SystemHigh

    [root@localhost oracle]# passwd oracle oracle账户创建密码

    Changing password for user oracle.

    New UNIX password:

    BAD PASSWORD: it is based on a dictionary word

    Retype new UNIX password:

    passwd: all authentication tokens updated successfully.

    3.3 创建目录

    创建目录并设置权限

    [root@localhost mytools]# mkdir -p programs/oracle/u01/app/oracle

    [root@localhost oracle]# mkdir -p u02/oradata

    [root@localhost programs]# chown -R oracle:oinstall oracle/ ./u01/app/oracle ./u02/oradata调整所有者

    [root@localhost programs]# chmod -R 755 oracle/ ./u01/app/oracle ./u02/oradata做调整访问权限

  • Linux下oracle10g的安装与配置及相关问题解决方案(一)

    2010-12-30 16:46:52Top 1 Digest 1

    第一部分 环境说明
    1.1 系统环境
    [root@localhost mysql]# uname -ar
    Linux localhost.localdomain 2.6.18-128.el5 #1 SMP Wed Jan 21 10:44:23 EST 2009 i686 i686 i386 GNU/Linux
    1.2 所需软件
    Oracle10g:10201_database_linux32.zip
    其他所需程序包的版本(或更高版本):
    • gcc-2.96-124
    • make-3.79
    • binutils-2.11
    • openmotif-2.1.30-11
    • glibc-2.2.4-31
    [root@localhost ~]# rpm -q gcc make  binutils openmotif glibc
    gcc-4.1.2-44.el5
    make-3.81-3.el5
    binutils-2.17.50.0.6-9.el5
    package openmotif is not installed
    glibc-2.5-34

    (系统提示package openmotif is not installed,下载openmotif并执行安装)
    [root@localhost building]# yum list openmotif (使用yum在线查找安装源)
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.163.com
     * updates: mirrors.163.com
     * addons: mirrors.163.com
     * extras: mirrors.163.com
    base                                                     | 2.1 kB     00:00    
    updates                                                  | 1.9 kB     00:00    
    addons                                                   |  951 B     00:00    
    extras                                                   | 2.1 kB     00:00    
    Available Packages
    openmotif.i386                      2.3.1-5.el5_5.1                      updates
    [root@localhost building]# yum install openmotif.i386 (yum安装openmotif)
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.163.com
     * updates: mirrors.163.com
     * addons: mirrors.163.com
     * extras: mirrors.163.com
    Setting up Install Process
    Parsing package install arguments
    Resolving Dependencies
    --> Running transaction check
    ---> Package openmotif.i386 0:2.3.1-5.el5_5.1 set to be updated
    filelists.sqlite.bz2                                     | 3.4 MB     00:07    
    filelists.sqlite.bz2                                     | 3.9 MB     00:08    
    filelists.sqlite.bz2                                     | 197 kB     00:00    
    filelists.xml.gz                                         |  195 B     00:00    
    --> Processing Dependency: libXp.so.6 for package: openmotif
    --> Running transaction check
    ---> Package libXp.i386 0:1.0.0-8.1.el5 set to be updated
    --> Finished Dependency Resolution

    Dependencies Resolved

    ================================================================================
     Package           Arch         Version                   Repository       Size
    ================================================================================
    Installing:
     openmotif         i386         2.3.1-5.el5_5.1           updates         1.5 M
    Installing for dependencies:
     libXp             i386         1.0.0-8.1.el5             base             23 k

    Transaction Summary
    ================================================================================
    Install      2 Package(s)        
    Update       0 Package(s)        
    Remove       0 Package(s)        

    Total download size: 1.5 M
    Is this ok [y/N]:y
    Complete!

    [root@localhost building]# rpm -q openmotif (安装完成后查找openmotif,存在,ok)
    openmotif-2.3.1-5.el5_5.1

  • Linux下mysql的安装配置与卸载及相关问题解决方案(三)

    2010-12-22 19:21:22Top 1 Digest 1

    1.  修改MySQL启动脚本/etc/rc.d/init.d/mysql,修改datadir=/var/lib/mysql的路径为变更后的目录:home/mysql_data/mysql

    # Set some defaults

    mysqld_pid_file_path=

    if test -z "$basedir"

    then

      basedir=/usr

      bindir=/usr/bin

      if test -z "$datadir"

      then

       # datadir=/var/lib/mysql

       datadir=/home/data/mysql

     

    2.  重启mysql服务

    [root@localhost mysql]#reboot 重启系统

    [root@localhost mysql]# /etc/rc.d/init.d/mysql start

    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

    出现此问题可以思考是否mysql服务已经启动

    [root@localhost init.d]# service mysql status

    因为mysql服务已经被注册为系统自启动服务,所以可以通过service mysql status查看mysql服务的状态,正在running

    MySQL running (4130)                                       [  OK  ]

    [root@localhost init.d]# service mysql stop (停止服务)

    Shutting down MySQL.                                       [  OK  ]

    [root@localhost init.d]# /etc/rc.d/init.d/mysql start

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

    (出现这个问题可以到/home/mysql_data/mysql目录下查看“mysql.sock”文件是否存在)

    [root@localhost mysql]# ls /home/mysql_data/mysql

    ibdata1                    mysql             test

    ib_logfile0                mysql-bin.000001  performance_schema

    ib_logfile1                mysql-bin.000002  RPM_UPGRADE_HISTORY

    localhost.localdomain.err  mysql-bin.000003  RPM_UPGRADE_MARKER-LAST

    localhost.localdomain.pid  mysql-bin.index  

    (果真不存在,找不到“mysql.sock”文件,所以不能使用/etc/rc.d/init.d/mysql start

    启动)

    [root@localhost mysql]# service mysql start  (使用service启动mysql服务)

    Starting MySQL.                                            [  OK  ]

    [root@localhost mysql]# ls    (查看/home/mysql_data/mysql下出现“mysql.sock”文件)

    ibdata1                    mysql             mysql.sock

    ib_logfile0                mysql-bin.000001  performance_schema

    ib_logfile1                mysql-bin.000002  RPM_UPGRADE_HISTORY

    localhost.localdomain.err  mysql-bin.000003  RPM_UPGRADE_MARKER-LAST

    localhost.localdomain.pid  mysql-bin.index   test

    [root@localhost mysql]# service mysql stop   (停止mysql服务)

    Shutting down MySQL.                                       [  OK  ]

    [root@localhost mysql]# /etc/rc.d/init.d/mysql start  (使用该命令重启,ok

    Starting MySQL.                                            [  OK  ]

    [root@localhost mysql]# /etc/rc.d/init.d/mysql status

    MySQL running (5730)        

    [root@localhost ~]# mysql -u root -p

    Enter password:

    Welcome to the MySQL monitor.  Commands end with ; or \g.

    Your MySQL connection id is 1

    Server version: 5.5.8-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.

    (创建数据库dbtest和表tbtest

     

    3.  备份与恢复

     

    7.1 备份:将上例创建的dbtest库备份到文件back_dbtest

    [root@localhost ~]# cd /home/mysql_data/mysql(进入库目录/home/mysql_data/mysql)

    [root@localhost ~]# mysqldump -u root -p --opt dbtest> back_dbtest

    7.2 恢复

    [root@localhost ~]# mysql -u root -p dbtest< back_dbtest

     

    1. 卸载mysql

    [root@localhost ~]# rpm -qa|grep -i mysql  (查看本机安装的mysql)

    MySQL-server-5.5.8-1.linux2.6

    MySQL-client-5.5.8-1.linux2.6

    [root@localhost ~]# rpm -ev MySQL-server-5.5.8-1.linux2.6 (执行卸载)

    卸载后/home/mysql_data/mysql中的数据及/etc/my.cnf不会删除,如果确定没用后就手工删除

    [root@localhost ~]#rm -f /etc/my.cnf

    [root@localhost ~]#rm -rf /home/mysql_data/mysql

  • Linux下mysql的安装配置与卸载及相关问题解决方案(二)

    2010-12-22 19:18:56Top 1 Digest 1

    说明:安装完client后直接执行不行,告诉我们不能连接到MySQL server,要求检查mysqld是否在运行并且socket文件'/var/lib/mysql/mysql.sock'是否存在

    1.  查看mysql默认端口号3306是否被占用

    1.1  netstat –an 命令查看mysql默认端口3306的情况,没有查找到

    [root@localhost bin]# netstat -an

    Active Internet connections (servers and established)

    Proto Recv-Q Send-Q Local Address   Foreign Address State     

    tcp   0  0 0.0.0.0:878  0.0.0.0:*   LISTEN     

    tcp   0  0 0.0.0.0:111  0.0.0.0:* LISTEN     

    tcp   0  0 127.0.0.1:631  0.0.0.0:*   LISTEN     

    tcp   0  0 127.0.0.1:25  0.0.0.0:*  LISTEN     

    tcp  0  0 192.168.10.249:56602   192.168.10.247:445   ESTABLISHED

    tcp   0    0 :::22     :::*     LISTEN     

    udp        0      0 0.0.0.0:40386               0.0.0.0:*                              

    udp        0      0 0.0.0.0:68                  0.0.0.0:*                               

    udp        0      0 0.0.0.0:872                 0.0.0.0:*                              

    udp        0      0 0.0.0.0:5353                0.0.0.0:*                              

    udp        0      0 0.0.0.0:875                 0.0.0.0:*                               

    udp        0      0 0.0.0.0:111                 0.0.0.0:*                              

    udp        0      0 0.0.0.0:631                 0.0.0.0:*                              

    udp        0      0 :::43145                    :::*                                    

    udp        0      0 :::5353                     :::*                                   

    Active UNIX domain sockets (servers and established)

    1.2  netstat -pan|grep 3306查看短款的情况也可以

    [root@localhost bin]# netstat -pan|grep 3306  #查询结果为空

    [root@localhost bin]#

    2.  紧接着进入/var/lib/mysql下面查看”mysql.sock”文件是否存在,不存在

    3.  [root@localhost /]# /etc/rc.d/init.d/mysql status

    MySQL is not running                                 [FAILED]

    通过上面的几种检查结果可以初步断定mysql服务还没有启动,那先启动mysql服务吧

    1. 启动mysql服务

    启动mysql的方式有很多

    1.  MySQL安装完成后启动文件mysql/etc/init.d目录下,在需要启动时运行下面命令即可。

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

     

    2.  停止服务

    [root@localhost]# /usr/bin/mysqladmin -u root -p shutdown

     

    3.  开机自启动

    一般情况下mysql安装完成后会被注册为系统服务,可以通过/sbin/chkconfig –list命令检查mysql是否被注册为系统服务

    [root@localhost /]# /sbin/chkconfig --list

    mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off

     

    如果已经注册则执行 service mysql start 启动服务,停止则service mysql stop

    [root@localhost sbin]# service mysql start

    Starting MySQL.                                            [  OK  ]

     

    如果没有注册则执行将mysql加入到系统的启动服务组里面去

    [root@localhost sbin]# /sbin/chkconfig -- add mysql

     

    MySQL从启动服务组里面删除

    [root@localhost sbin]# /sbin/chkconfig --del mysql

     

    4.  继续上面的操作,修改mysqlroot用户的密码

    [root@localhost bin]# mysqladmin -uroot password "manager"   成功

     

    5.  重新进入/var/lib/mysql/查看 mysql.sock文件存在了

    [root@localhost mysql]# ls /var/lib/mysql

    ibdata1      ib_logfile1                localhost.localdomain.pid  mysql.sock          RPM_UPGRADE_HISTORY      test

    ib_logfile0  localhost.localdomain.err  mysql                      performance_schema  RPM_UPGRADE_MARKER-LAST

    [root@localhost mysql]#

    2. 进入mysql数据库

    [root@localhost bin]# mysql -u root -p

    Enter password:

    Welcome to the MySQL monitor.  Commands end with ; or \g.

    Your MySQL connection id is 7

    Server version: 5.5.8 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> show databases;

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

    | Database           |

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

    | information_schema |

    | mysql              |

    | performance_schema |

    | test               |

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

    4 rows in set (0.00 sec)

     

    3. 优化mysql,更改mysql目录

    MySQL默认的数据文件存储目录为/var/lib/mysql。假如要把目录移到/home/mysql_data目录需要如下操作:

    1.  创建mysql_data目录

    [root@localhost mysql]# mkdir /home/mysql_data

    [root@localhost mysql]# cd /home

    [root@localhost home]# ls

    lost+found  mysql  mysql_data  sunny

     

    2.  未保证mysql所有文件正常且不被损坏或占用,在调整目录前需要停止mysql服务或者杀掉mysql进程

    [root@localhost home]# /usr/bin/mysqladmin -u root -p  shutdown (杀掉mysql进程)

    Enter password:

    [root@localhost home]#service mysql stop    (停止mysql服务)

     

    3.  /var/lib/mysql整个目录移到/home/data

    [root@localhost home]# mv /var/lib/mysql/ /home/mysql_data/

    [root@localhost home]#

     

    4.  修改配置文件my.cnf

    配置文件一般都在/etc目录下,如果/etc/目录下没有my.cnf配置文件,则需要到/usr/share/mysql/下找到*.cnf文件,拷贝其中一个(比如:my-medium.cnf)到/etc/目录下,并重命名为my.cnf

     

    [root@localhost home]# ls /usr/share/mysql/*.cnf

    /usr/share/mysql/my-huge.cnf             /usr/share/mysql/my-large.cnf   /usr/share/mysql/my-small.cnf

    /usr/share/mysql/my-innodb-heavy-4G.cnf  /usr/share/mysql/my-medium.cnf

    [root@localhost home]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

    [root@localhost home]# find /etc/my.cnf

    /etc/my.cnf

    [root@localhost home]#

     

    为保证mysql能够正常工作,需要编辑my.conf,调整mysql.sock文件的指向位置

     

    [client]

    #password       = your_password

    port            = 3306

    #socket         = /var/lib/mysql/mysql.sock

    socket = /home/mysql_data/mysql/mysql.sock

     

    # Here follows entries for some specific programs

     

    # The MySQL server

    [mysqld]

    port            = 3306

    #socket         = /var/lib/mysql/mysql.sock

    socket = /home/mysql_data/mysql/mysql.sock

    skip-external-locking

     

    <P class=MsoListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l3 level1 lfo4; ms
  • Linux下mysql的安装配置与卸载及相关问题解决方案(一)

    2010-12-22 19:15:45Top 1 Digest 1

    (一)   挂载目录,使windowslinux成功通信

    1.  首先在windows上面建立一个共享目录 @share_folder,并将所需的安装软件放置到该目录

    2.  进入linux进行挂载

    mount –t cifs –o username=”your_windows_username”, (请忽略回车)

    password=”your_windows_password” (此处空格,请忽略回车)

    //your_windows_ip_address/\@share_folder  /linux挂载区

    例子:mount –t cifs –o username=”mylovedog”,password=”123456” //192.168.1.10/\@share_folder /mnt

    3.  进入linux终端,在/usr/local/下创建mytools目录,并将/mnt下的mysql安装文件拷贝到/usr/local/mytools目录下

    cd /usr/local

    mkdir mytools

    cp /mnt/Mysql-* /usr/local/mytools

    4.  本文使用的安装程序为:

    [root@localhost mysql]# uname -ar

    Linux localhost.localdomain 2.6.18-128.el5 #1 SMP Wed Jan 21 10:44:23 EST 2009 i686 i686 i386 GNU/Linux

     

    [root@localhost mysql]# ls /usr/local/mytools/  (官网下载)

    MySQL-client-5.5.8-1.linux2.6.i386.rpm  MySQL-server-5.5.8-1.linux2.6.i386.rpm

    (二)   mysql 的安装与配置

    1. 安装mysql server

    [root@localhost mytools]# rpm -ivh MySQL-server-5.5.8-1.linux2.6.i386.rpm

    Preparing...               ########################################### [100%]

    1:MySQL-server           ########################################### [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 localhost.localdomain 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!

    说明:

    1.  出现以上信息,表明已经安装成功,需要到/usr/bin下设置root账号

    2.  RPMRedHat Package Manager)语法解析:

    2.1 RPM 是以一种数据库记录的方式来将你所需要的套件安装到你的 Linux 主机的一套管理程序

    2.2 语法:rpm 参数 待安装程序.rpm

    2.3 主要安装以rpm结尾的安装包,还有*.src.rpm结尾的,需要先SRPMSource Code)编译成RPM,然后再安装

    2.4 RPM安装的程序都会被安装到预设目录中:

    /etc

    一些设定文件放置的目录,例如 /etc/crontab

    /usr/bin

    一些可执行档案

    /usr/lib

    一些程序使用的动态函式库

    /usr/share/doc

    一些基本的软件使用手册与说明文件

    /usr/share/man

    一些 man page 档案

    2. 进入/usr/bin目录设定mysqlroot账户密码

    [root@localhost mytools]# /usr/bin/mysqladmin -u root password “manager”

    bash: /usr/bin/mysqladmin: No such file or directory

     

    说明:系统提示找不到mysqladmin这个文件或目录,怎么办呢?开始排错吧:

    1.   首先就是到/usr/bin目录下面查看所有以mysql开头的内容(ll mysql*),共发现14个文件或目录(mysqlbugmysql_convert_table_formatmysqld_multimysqld_safemysqldumpslowmysql_fix_extensionsmysqlhotcopymysql_install_dbmysql_secure_installationmysql_setpermissionmysqltestmysql_tzinfo_to_sqlmysql_upgrademysql_zap)确实没有mysqladmin,那又是什么原因呢?

    2.   再去查看一下mysql server安装完成后各目录中的文件变化吧

    2.1 数据库目录 /var/lib/mysql/

    2.2 配置文件目录 /usr/share/mysqlmysql.server命令及配置文件)

    2.3 相关命令所在目录 /usr/bin

    2.4  启动脚本/etc/init.d(启动脚本文件mysql的目录)

    3.   网上资料说只有安装了mysql-client端才会出现mysqladmin

    mysqladmin is part of the mysql-client package, so you have to install that package in order to use mysqladmin, mysql etc

    3. 安装mysql client

    [root@localhost mytools]# rpm -ivh MySQL-client-5.5.8-1.linux2.6.i386.rpm

    Preparing...                ########################################### [100%]

    1:MySQL-client           ########################################### [100%]

     

    说明:安装完成后查看(ll /usr/bin/mysql*,/usr/bin/目录下多了很多文件,由安装完server后的14个,变成了26个,并且有了mysqladmin文件

    mysql

    mysqlaccess

    mysqlaccess.conf

    mysqladmin

    mysqlbinlog

    mysqlbug

    mysqlcheck

    mysql_convert_table_format

    mysqld_multi

    mysqld_safe

    mysqldump

    mysqldumpslow

    mysql_find_rows

    mysql_fix_extensions

    mysqlhotcopy

    mysqlimport

    mysql_install_db

    mysql_secure_installation

    mysql_setpermission

    mysqlshow

    mysqlslap

    mysqltest

    mysql_tzinfo_to_sql

    mysql_upgrade

    mysql_waitpid

    mysql_zap 

    4. 设置mysqlroot管理员账号密码

    [root@localhost bin]# mysqladmin -u root password manager

    mysqladmin: connect to server at 'localhost' failed

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

    Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!

     

    说明:安装完client后直接执行不行,告诉我们不能连接到MySQL server,要求检查mysqld是否在运行并且socket文件'/var/lib/mysql/mysql.sock'是否存在

    1.  查看mysql默认端口号3306是否被占用

    1.1  netstat –an 命令查看mysql默认端口3306的情况,没有查找到

    [root@localhost bin]# netstat -an

    Active Internet connections (servers and established)

    Proto Recv-Q Send-Q Local Address   Foreign Address State     

    tcp   0  0 0.0.0.0:878  0.0.0.0:*   LISTEN     

    tcp   0  0 0.0.0.0:111  0.0.0.0:* LISTEN     

    tcp   0  0 127.0.0.1:631  0.0.0.0:*   LISTEN     

    tcp   0  0 127.0.0.1:25  0.0.0.0:*  LISTEN     

  • 一条sql语句解决了一个变态需求

    2013-11-19 17:05:11

    变态需求:

    数据库中找100张表,每张表都count(*)出当前记录,然后得到将所有记录的和。


    一个sql解决:

    SELECT  SUM(NUM_ROWS) FROM DBA_ALL_TABLES WHERE WNER='你的当前用户';

    备注:当前的用户必须用大写,其他的比如NUM_ROWS, DBA_ALL_TABLES, OWNER也必须大写

Open Toolbar