• Linux下安装MySQL


    安装环境:Linux服务器CentOS 5.5

    安装版本:mysql-5.5.8.tar.gz

    1、安装 cmake 编译器。

    1)、下载cmake

    #cd /usr/local/src

    #wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz

    2)、解压cmake

    #tar -zvxf cmake-2.8.4.tar.gz

    3)、配置编译

    #cd cmake-2.8.4
    #yum -y install gcc
    #yum -y install gcc-c++
    #yum -y install ncurses-devel
    #./configure
    #make
    #make install

    2、安装MySQL

    1)、下载MySQL。

    #cd /usr/local/src

    #wget http://sdk.ruiya.com/linux/mysql-5.5.9.tar.gz

    2)、添加必要的组和拥有者

    #groupadd mysql

    #useradd -r -g mysql mysql

    3)、解压MySQL

    #tar -zvxf mysql-5.5.9.tar.gz

    4)、配置编译

    如果是重装MySql,请先删除my.cnf如: rm -rf /etc/my.cnf

    #mkdir /usr/local/mysql

    #mkdir /usr/local/mysql/data

    #cd /usr/local/src/mysql-5.5.9

    #cmake .
    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
    -DINSTALL_DATADIR=/usr/local/mysql/data
    -DDEFAULT_CHARSET=utf8
    -DDEFAULT_COLLATION=utf8_general_ci
    -DEXTRA_CHARSETS=all
    -DENABLED_LOCAL_INFILE=1

    参数说明:

    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql        //安装目录
    -DINSTALL_DATADIR=/usr/local/mysql/data         //数据库存放目录
    -DDEFAULT_CHARSET=utf8                        //使用utf8字符
    -DDEFAULT_COLLATION=utf8_general_ci            //校验字符
    -DEXTRA_CHARSETS=all                            //安装所有扩展字符集
    -DENABLED_LOCAL_INFILE=1                        //允许从本地导入数据

    #make

    #make install

    注意事项:

    重新编译时,需要清除旧的对象文件和缓存信息。 

    # make clean
    # rm -f  CMakeCache.txt
    # rm -rf /etc/my.cnf 

    4)、设置目录权限

    # cd /usr/local/mysql

    # chown -R root:mysql . //把当前目录中所有文件的所有者所有者设为root,所属组为mysql

    # chown -R mysql:mysql data
     

    5)、配置文件

    # cp support-files/my-medium.cnf /etc/my.cnf //这个配置仅适合小内存系统(32M - 64M)

    打开如下注释

    innodb_data_home_dir = /usr/local/mysql/data
    innodb_data_file_path = ibdata1:10M:autoextend
    innodb_log_group_home_dir = /usr/local/mysql/data

    innodb_buffer_pool_size = 16M
    innodb_additional_mem_pool_size = 2M

    innodb_log_file_size = 5M
    innodb_log_buffer_size = 8M
    innodb_flush_log_at_trx_commit = 1
    innodb_lock_wait_timeout = 50

    添加默认字符集

    [client] 
    default-character-set = utf8                                        // 添加编码支持
    [mysqld]
    default-character-set = utf8  或 character_set_server  // 添加编码支持
    max_connections = 10000                                          //根据服务器性能调节
    basedir = /usr/local/mysql                                     //设置安装目录,这样在系统启动时才能正确运行到/etc/rc.d/init.d/mysql start

    6)、创建系统数据库的表

    # cd /usr/local/mysql

    # scripts/mysql_install_db --user=mysql

    7)、设置权限启动

    设置环境变量

    # vi /root/.bash_profile

    在PATH=$PATH:$HOME/bin添加参数为:

    PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib

    #source /root/.bash_profile

    手动启动MySQL 

    # cd /usr/local/mysql

    # ./bin/mysqld_safe --user=mysql &   //启动MySQL,但不能停止

    启动日志写在此文件下:/usr/local/mysql/data/localhost.err

    关闭MySQL服务

    # mysqladmin -u root -p shutdown  //这里MySQL的root用户还没有配置密码,所以为空值。

    通过脚本启动MySQL

    cp support-files/mysql.server  /etc/init.d/mysql

    然后再用#service mysql start 来启动mysql即可。

    8)、修改MySQL的root用户的密码

    # mysql -u root mysql

    mysql>use mysql;
    mysql>desc user;
    mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";  //为root添加远程连接的能力。
    mysql>update user set Password = password('xxxxxx') where User='root';
    mysql>select Host,User,Password  from user where User='root'; 
    mysql>flush privileges;
    mysql>exit

    重新登录:mysql -u root -p

    注意事项:

    <1>、MySQL5.5 默认使用InnoDB作为存储引擎,所以可以不设置DWITH_MYISAM_STORAGE_ENGINE值

    参考:

    如何打开MySQL中root账户的远程登录 

    mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";
    注意%对应的密码,如果不相同,可以通过 update user set Password = password('xxxxxx') where User='root'; 修改。

    同时注意防火墙是否已关闭或者添加例外。

    # /etc/rc.d/init.d/iptables stop

    关闭或开启Linux/CentOS上的防火墙 

    导出数据库生成SQL脚本
    mysqldump -h 192.168.200.18  -u root -p TestDB > TestDB.sql

    <2>、测试mysql守护进程。

    #cd /usr/local/mysql/mysql-test ;

    #perl mysql-test-run.pl

    <3>、注意事项:

    复制代码
    To start mysqld at boot time you have to copy
    support
    -files/mysql.server to the right place for your system

    PLEASE REMEMBER
    TOSET A PASSWORD FOR THE MySQL root USER !
    To do so, start the server, then issue the following commands:

    /usr/local/mysql/bin/mysqladmin -u root password 'new-password'
    /usr/local/mysql/bin/mysqladmin -u root -h localhost password 'new-password'

    Alternatively you can run:
    /usr/local/mysql/bin/mysql_secure_installation

    which will also give you the
    optionof removing the test
    databases
    and anonymous user created bydefault. This is
    strongly recommended
    for production servers.

    See the manual
    for more instructions.

    You can start the MySQL daemon
    with:
    cd
    /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

    You can test the MySQL daemon
    with mysql-test-run.pl
    cd
    /usr/local/mysql/mysql-test ; perl mysql-test-run.pl

    Please report
    any problems with the /usr/local/mysql/scripts/mysqlbug script!
  • 相关阅读:
    溢出省略号
    自定义字体
    jquery实现上一页下一页
    集成学习理解
    常用命令-python篇
    python 多进程和多线程
    10预处理命令上
    9函数
    8指针2
    7指针1
  • 原文地址:https://www.cnblogs.com/andy24/p/3409806.html
Copyright © 2020-2023  润新知