• Linux系统安装MySQL步骤及支持远程操作配置方法


    一、数据库安装(安装在/usr/local目录)

    1. 压缩包拷贝到/users/lengyufang/tools

    2. groupadd mysql
    3. useradd -r -g mysql -s /bin/false mysql
    4. cd /usr/local
    5. tar zxvf /users/lengyufang/tools/mysql-5.5.48-linux2.6-x86_64.tar.gz
    6. ln -s mysql-5.5.48-linux2.6-x86_64 mysql
    7. cd mysql
    8. chown -R mysql .
    9. chgrp -R mysql .
    10. scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    11. chown -R root .
    12. chown -R mysql data
    13. cp support-files/my-medium.cnf /etc/my.cnf
    14. bin/mysqld_safe --user=mysql1 &
    15. ln -s /usr/local/mysql/bin/mysql /usr/bin
    ln -s /usr/local/mysql-5.5.48-linux2.6-x86_64/bin/mysqladmin /usr/bin

    以下步骤安装在 /users/mysql目录

    2. groupadd mysql
    3. useradd -r -g mysql -s /bin/false mysql
    4. cd /users/mysql
    5. tar zxvf /users/lengyufang/tools/mysql-5.5.48-linux2.6-x86_64.tar.gz
    6. ln -s mysql-5.5.48-linux2.6-x86_64 mysql
    7. cd mysql
    8. chown -R mysql .
    9. chgrp -R mysql .
    10. scripts/mysql_install_db --user=mysql --basedir=/users/mysql/mysql --datadir=/users/mysql/mysql/data
    11. chown -R root .
    12. chown -R mysql data
    13. cp support-files/my-medium.cnf /etc/my.cnf
    14. bin/mysqld_safe --user=mysql &
    15. ln -s /users/mysql/mysql/bin/mysql /usr/bin
    ln -s /users/mysql/mysql-5.5.48-linux2.6-x86_64/bin/mysqladmin /usr/bin

    二、设置数据库登陆密码

    默认安装后,登陆mysql不用密码

    [zhangqi@A10122901 ~]$ mysql
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 2
    Server version: 5.5.48-log 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> 

    为了保证安全,设置mysql登陆密码的重要性不言而喻。方法如下:

    shell下执行:


    /usr/bin/mysqladmin -u root password 123456 #密码是123456

    [root@test1 local]# mysql
        ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)
        显示错误,说明密码已经修改。

    三、数据库支持远程访问设置
    1、mysql -u root -p
       然后输入密码

    2、use mysql;

    3、grant all privileges on *.* to root@"%" identified by "123456";

    四、远程访问数据库

    mysql -h 10.43.114.4 -u root -p 123456 db_code_cover -e "select * from tbl_code_cover"

    #db_code_cover是数据库名,tbl_code_cover是db_code_cover下的数据表

    注意,以上语法是在shell下执行mysql语句的方法。

    熟悉mysql的人都知道,select * from tbl_code_cover是标准的mysql环境下的执行语句。


    五、查看数据库数据的存放目录

    1、mysql -u root -p
       然后输入密码

    2、show variables like 'datadir%';

       MySQL [db_code_cover]> show variables like 'datadir%';
    +---------------+--------------------------+
    | Variable_name | Value                    |
    +---------------+--------------------------+
    | datadir       | /users/mysql/mysql/data/ |
    +---------------+--------------------------+

    1 row in set (0.00 sec)

    value值表明数据文件的位置是/users/mysql/mysql/data/

    注意,步骤一中的第10步 scripts/mysql_install_db --user=mysql --basedir=/users/mysql/mysql --datadir=/users/mysql/mysql/data

    会指定数据库文件位置。

  • 相关阅读:
    Codeforces 631A Interview【模拟水题】
    Codeforces 651E Table Compression【并查集】
    Codeforces 651D Image Preview【二分+枚举】
    Codeforces 651C Watchmen【模拟】
    Codeforces 651B Beautiful Paintings【贪心】
    18.06.26 16年期末10:游览规划
    18.06.25 POJ4129 16年期末09:变换的迷宫
    18.06.25 POJ4150 16年期末07:上机
    18.06.25 16年期末06 42点
    18.06.25 16年期末01-05集合
  • 原文地址:https://www.cnblogs.com/onetwo/p/5435790.html
Copyright © 2020-2023  润新知