zoukankan      html  css  js  c++  java
  • MySQL入门篇(一)之MySQL部署

    • MySQL 二进制免编译安装

     (1)下载二进制免编译版本mysql 5.6.35

    [root@localhost tools]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
    (2)增加mysql运行用户
    [root@localhost tools]# useradd -s /sbin/nologin -M mysql
    (3)解压并移动Mysql到指定的安装路径
    [root@localhost tools]# tar -zxf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
    [root@localhost tools]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql-5.6.35
    (4)创建软连接并更改目录所属
    [root@localhost tools]# ln -sv /usr/local/mysql-5.6.35 /usr/local/mysql
    ‘/usr/local/mysql’ -> ‘/usr/local/mysql-5.6.35’
    [root@localhost mysql]# chown -R mysql.mysql /usr/local/mysql
    (5)初始化Mysql
    [root@localhost mysql]# scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
    (6)拷贝Mysql启动脚本,并修改脚本权限启动
    [root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
    [root@localhost mysql]# chmod 755 /etc/init.d/mysqld 
    [root@localhost mysql]# vim /etc/init.d/mysqld 
    basedir=/usr/local/mysql
    datadir=/usr/local/mysql/data
    [root@localhost mysql]# cp support-files/my-default.cnf /etc/my.cnf
    [root@localhost mysql]# /etc/init.d/mysqld start
    Starting MySQL.Logging to '/usr/local/mysql/data/localhost.err'.
    ... SUCCESS! 
    [root@localhost mysql]# netstat -tulnp |grep 3306
    tcp6       0      0 :::3306                 :::*                    LISTEN      62679/mysqld  
    (7)加入开机启动,测试登录    
    [root@localhost mysql]# chkconfig --add mysqld
    [root@localhost mysql]# chkconfig mysqld on
    [root@localhost mysql]# export PATH=/usr/local/mysql/bin/:$PATH
    [root@localhost mysql]# mysql
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 1
    Server version: 5.6.35 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2016, 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> quit;
    (8)mysql安全设置
    [root@localhost mysql]# mysqladmin -uroot password '123456'        //配置mysql的root用户密码
    Warning: Using a password on the command line interface can be insecure.
    [root@localhost mysql]# mysql
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
    [root@localhost mysql]# mysql -uroot -p123456 -e "show databases;"
    Warning: Using a password on the command line interface can be insecure.
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | test               |
    +--------------------+
    
    [root@localhost mysql]# mysql -uroot -p        //清理无用的Mysql用户和库
    Enter password: 
    
    mysql> select user,host from mysql.user;
    +------+-----------+
    | user | host      |
    +------+-----------+
    | root | 127.0.0.1 |
    | root | ::1       |
    |      | localhost |
    | root | localhost |
    +------+-----------+
    4 rows in set (0.01 sec)
    
    mysql> drop user "root"@"::1"
        -> ;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> drop user ""@"localhost";
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> select user,host from mysql.user;
    +------+-----------+
    | user | host      |
    +------+-----------+
    | root | 127.0.0.1 |
    | root | localhost |
    +------+-----------+
    2 rows in set (0.00 sec)
    
    有时使用drop命令删除不了用户,可能是大写或者是特殊的Linux主机名导致的,如下:
    mysql> drop user ''@'MySQL';
    ERROR 1396 (HY000): Operation DROP USER failed for ''@'mysql'
    
    解决办法如下:
    mysql> delete from mysql.user where user='' and host='MySQL';
    mysql> flush privileges;
  • 相关阅读:
    微服务负载均衡技术
    dubbo 协议注册中心
    dubbo 元数据中心
    @Autowired 写在构造方法上
    onchange事件 is not defined
    转:JNDI的本质及作用
    The valid characters are defined in RFC 7230 and RFC 3986报错处理
    FOR XML PATH 简单介绍
    ROW_NUMBER() OVER函数的基本用法
    java和js中JSONObject,JSONArray,Map,String之间转换
  • 原文地址:https://www.cnblogs.com/linuxk/p/9365938.html
Copyright © 2011-2022 走看看