美文网首页我爱编程
Mysql部署及基础命令

Mysql部署及基础命令

作者: 三旬爱生活 | 来源:发表于2018-05-15 14:58 被阅读21次

    1、下载软件

    使用本地已下好的包 用rz上传至linux

    安装上传包:yum -y install lrzsz

    rz 选择mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz上传
    2、查看是否安装

    ps -ef|grep mysqld
    

    3、查看是否有rpm包

    rpm -qa |grep -i mysql
    4、解压并移动到mysql目录

    tar xzvf mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz

    mv mysql-5.6.23-linux-glibc2.5-x86_64 mysql
    5、创建用户和组

    新建dba组:groupadd -g 101 dba

    创建用户并添加dba组:useradd -u 514 -g dba -G root -d /usr/local/mysql mysqladmin

    ps:生产环境中一般不会给root权限

    先申请sudo权限,再创建一个mysql服务的管理用户

    创建mysqladmin作用:1、一个用户只对一个组件 2、dba组
    6、修改密码

    passwd mysqladmin
    7、拷贝配置文件到mysqladmin用户的家目录

    cp /etc/skel/.* /usr/local/mysql
    8、配置/etc/my.cnf:直接覆盖

    vi /etc/my.cn 先dg 在黏贴

    [client]

    port = 3306

    socket = /usr/local/mysql/data/mysql.sock

    [mysqld]

    port = 3306

    socket = /usr/local/mysql/data/mysql.sock

    skip-external-locking

    key_buffer_size = 256M

    sort_buffer_size = 2M

    read_buffer_size = 2M

    read_rnd_buffer_size = 4M

    query_cache_size= 32M

    max_allowed_packet = 16M

    myisam_sort_buffer_size=128M

    tmp_table_size=32M

    table_open_cache = 512

    thread_cache_size = 8

    wait_timeout = 86400

    interactive_timeout = 86400

    max_connections = 600

    Try number of CPU's*2 for thread_concurrency

    thread_concurrency = 32

    isolation level and default engine

    default-storage-engine = INNODB

    transaction-isolation = READ-COMMITTED

    server-id = 1

    basedir = /usr/local/mysql

    datadir = /usr/local/mysql/data

    pid-file = /usr/local/mysql/data/hostname.pid

    open performance schema

    log-warnings

    sysdate-is-now

    binlog_format = MIXED

    log_bin_trust_function_creators=1

    log-error = /usr/local/mysql/data/hostname.err

    log-bin=/usr/local/mysql/arch/mysql-bin

    other logs

    general_log =1

    general_log_file = /usr/local/mysql/data/general_log.err

    slow_query_log=1

    slow_query_log_file=/usr/local/mysql/data/slow_log.err

    for replication slave

    log-slave-updates

    sync_binlog = 1

    for innodb options

    innodb_data_home_dir = /usr/local/mysql/data/

    innodb_data_file_path = ibdata1:500M:autoextend

    innodb_log_group_home_dir = /usr/local/mysql/arch

    innodb_log_files_in_group = 2

    innodb_log_file_size = 200M

    innodb_buffer_pool_size = 2048M

    innodb_additional_mem_pool_size = 50M

    innodb_log_buffer_size = 16M

    innodb_lock_wait_timeout = 100

    innodb_thread_concurrency = 0

    innodb_flush_log_at_trx_commit = 1

    innodb_locks_unsafe_for_binlog=1

    innodb io features: add for mysql5.5.8

    performance_schema

    innodb_read_io_threads=4

    innodb-write-io-threads=4

    innodb-io-capacity=200

    purge threads change default(0) to 1 for purge

    innodb_purge_threads=1

    innodb_use_native_aio=on

    case-sensitive file names and separate tablespace

    innodb_file_per_table = 1

    lower_case_table_names=1

    [mysqldump]

    quick

    max_allowed_packet = 16M

    [mysql]

    no-auto-rehash

    [mysqlhotcopy]

    interactive-timeout

    [myisamchk]

    key_buffer_size = 256M

    sort_buffer_size = 256M

    read_buffer = 2M

    write_buffer = 2M

    修改innodb_buffer_pool_size = 2048M为1024M
    9、修改配置文件及mysql目录的权限及所有人/组

    修改配置文件:chown mysqladmin:dba /etc/my.cnf chmod 640 /etc/my.cnf

    修改目录:chown -R mysqladmin:dba /usr/local/mysql chmod -R 755 /usr/local/mysql
    10、切换到mysqladmin用户

    su - mysqldamin
    11、查看当前路径 新建归档目录

    pwd /usr/local/mysql

    mkdir arch
    12、安装

    scripts/mysql_install_db --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    13、配置mysql服务,并改为开机启动

    1.root用户先切换到mysql根目录 cd /usr/local/mysql

    2.root用户下将服务文件拷贝到init.id下,并重命名为mysql cp support-files/mysql.server /etc/rc.d/init.d/mysql

    3.赋予可执行权限: chmod +x /etc/rc.d/init.d/mysql

    4.添加服务 : chkconfig --add mysql

    5.设置开机启动: chkconfig --level 345 mysql on
    14、启动mysql并查看流程和监听

    1.切换用户:su - mysqladmin

    2.rm -rf my.cnf

    bin/mysqld_safe &

    3.查看进程及端口号

    ps -ef|grep mysqld

    netstat -tulnp | grep mysql
    15、查看mysql服务

    service mysql status
    16、登录mysql

    [mysqladmin@hadoop001 ~]$ mysql

    mysql>
    17、查看数据库

    mysql>show databases;

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

    | Database |

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

    | information_schema |

    | mysql |

    | performance_schema |

    | test |

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

    4 rows in set (0.02 sec)
    18、更新密码及清除用户

    1.进入数据库mysql:

    use mysql

    Database changed

    2.查看用户表:select host,user,password from user;

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

    | host | user | password |

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

    | localhost | root | |

    | hadoop001 | root | |

    | 127.0.0.1 | root | |

    | ::1 | root | |

    | localhost | | |

    | hadoop001 | | |

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

    6 rows in set (0.00 sec)

    3.更新root用户密码为‘123456’:update user set password=password('123456') where user='root';

    Query OK, 4 rows affected (0.02 sec)

    Rows matched: 4 Changed: 4 Warnings: 0

    4.再次查看用户表:select host,user,password from user;

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

    | host | user | password |

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

    | localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

    | hadoop001 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

    | 127.0.0.1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

    | ::1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

    | localhost | | |

    | hadoop001 | | |

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

    6 rows in set (0.00 sec)

    密码已更新
    19、MySQL重新部署

    1. rm -rf arch/* data/* 删除归档文件及数据文件

    2. scripts/mysql_install_db --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 重新部署
      20、修改% 任意机器可访问

    update mysql.user set Host='%' where Host='hadoop000';

    flush privileges;

    安装dbeaver 工具链接 即可连接到数据库
    21、mysql命令参数

    mysql -uroot -p123456

    mysql -u root -p123456

    mysql -u root -p 123456 不可以(空格会代表一位密码)

    mysql -u root -p123456 -h192.168.137.251

    mysql -u root -p123456 -hlocalhost mysql
    22、创建数据库及用户

    create database ruozedb; 创建数据库

    grant all privileges on ruozedb.* to hutu@'192.167.137.2' identified by '123456'; 新建账号密码并授权

    flush privileges; dbeaver登录
    23、查看进程

    show processlist;
    24、杀死进程

    kill id(没有-9)

    作者:糊涂蟲
    链接:https://www.jianshu.com/p/db55504617bc
    來源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

    相关文章

      网友评论

        本文标题:Mysql部署及基础命令

        本文链接:https://www.haomeiwen.com/subject/cnaedftx.html