• Linux 安装 Mysql 数据库


     
    安装环境:系统是 centos6.5
        下载地址:http://dev.mysql.com/downloads/mysql/5.6.html#downloads
        下载版本:我这里选择的5.6.33,通用版,linux下64位
        也可以直接复制64位的下载地址,通过命令下载:wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
     
     
    安装步骤
    0、卸载老版本MySQL

    查找并删除mysql有关的文件

    find / -name mysql

    rm -rf 上边查找到的路径,多个路径用空格隔开,或者下边一条命令即可 

    find / -name mysql|xargs rm -rf

     
     
    1、在安装包存放目录下执行命令解压文件:
    mkdir /usr/local/mysql
    tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
    mv 改名操作 或者 复制cp, 总之是让tar解压后的文件到mysql目录下即可
     
    2、删除安装包,重命名解压后的文件
    rm -f mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz 
    mv mysql-5.6.31-linux-glibc2.5-x86_64/ mysql
     
    3、添加mysql用户组和mysql用户
    先检查是否有mysql用户组和mysql用户
    groups mysql
     
    若无,则添加;
    groupadd mysql 
    
    useradd -r -g mysql mysql
     
    若有,则跳过;
     
    4、进入mysql目录更改权限
    cd mysql/ 
    chown -R mysql:mysql ./
     
    5、执行安装脚本
    ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
     
    此时遇到错误Data:Dummper ,通过
    yum install autoconf
    解决。
     
    安装完之后修改当前目录拥有者为root用户,修改data目录拥有者为mysql
    chown -R root:root ./
    chown -R mysql:mysql data

     
    6、更改mysql密码

    先启动mysql

    ./support-files/mysql.server start
    如果MySQL启动报错,则可能是已经存在MySQL进程,杀掉即可
    ps aux|grep mysql kill -9 上边的进程号 #或者下边一条命令即可杀掉所有MySQL进程 ps aux|grep mysql|awk '{print $2}'|xargs kill -9
     
    杀掉后再启动即可。
     
    上一步安装脚本执行输出的日志中告诉我们如何更改密码了
     

    MySQL启动之后再执行如下命令更改密码:

    ./bin/mysqladmin -u root -h localhost.localdomain password 'root'
     
    警告可以暂时忽略,密码更改后即可登录MySQL
    ./bin/mysql -h127.0.0.1 -uroot -proot
     
    登录之后将其他用户的密码也可改为root
    update mysql.user set password=password('root') where user='root'; 
    flush privileges;
     
    7、更改环境变量:
    vim /etc/profile
    
    加入:
    export PATH="/usr/local/mysql/bin:$PATH"
    
    最后执行立即生效:
    source /etc/profile
    8、增加远程登录权限
    上一步即可本地登录,但远程登录会报错
     其它主机无法通过nav连接的主要原因在3306端口没打开。

    a.Centos7 的打开端口方法 , 其它系统不一样

    firewall-cmd --zone=public --add-port=3306/tcp --permanent
    
    firewall-cmd --reload 防火墙重启
    
    firewall-cmd --state 查看防火墙状态
    
    firewall-cmd --list-ports 查看打开端口

    b.Mysql打开远程权限

    登陆mysql后执行:

    grant all privileges on *.* to root@'%' identified by 'root'; 
    flush privileges;
     
    执行之后即可远程登录
     
     
    9、将MySQL加入Service系统服务
    cp support-files/mysql.server /etc/init.d/mysqld 
    chkconfig --add mysqld
    chkconfig mysqld on 
    service mysqld restart  
    service mysqld status
     
     
    10、配置my.cnf
    vim my.cnf #添加以下两条语句并保存退出 
    
    default-character-set=utf8 
    
    lower_case_table_names=1 
    
    max_allowed_packet=100M
     
    配置好之后,重启mysqld服务
     
     另外:
    当需数据库存储表情时可如下配置数据库的配置文件 my.cnf
     1 # For advice on how to change settings please see
     2 # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
     3 # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
     4 # *** default location during install, and will be replaced if you
     5 # *** upgrade to a newer version of MySQL.
     6 
     7 [client]
     8 default-character-set=utf8mb4
     9 
    10 [mysqld]
    11 character-set-server=utf8mb4
    12 
    13 collation-server=utf8mb4_unicode_ci
    14 
    15 init-connect="SET NAMES utf8mb4"
    16 
    17 log-bin=mysql-bin
    18 
    19 binlog_format=mixed
    20 
    21 
    22 #lower_case_table_names=1
    23 max_allowed_packet=100M
    24 
    25 
    26 #server-id=179
    27 
    28 # Remove leading # and set to the amount of RAM for the most important data
    29 # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    30 # innodb_buffer_pool_size = 128M
    31 
    32 # Remove leading # to turn on a very important data integrity option: logging
    33 # changes to the binary log between backups.
    34 # log_bin
    35 
    36 # These are commonly set, remove the # and set as required.
    37 # basedir = .....
    38 # datadir = .....
    39 # port = .....
    40 # server_id = .....
    41 # socket = .....
    42 
    43 # Remove leading # to set options mainly useful for reporting servers.
    44 # The server defaults are faster for transactions and fast SELECTs.
    45 # Adjust sizes as needed, experiment to find the optimal values.
    46 # join_buffer_size = 128M
    47 # sort_buffer_size = 2M
    48 # read_rnd_buffer_size = 2M 
    49 
    50 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
     
  • 相关阅读:
    Redis配置参数详解
    amoeba实现读写分离
    P1525 关押罪犯 并查集
    模板汇总——treap
    差分约束
    HDU
    CodeForces 522C Chicken or Fish?
    CodeForces 812E Sagheer and Apple Tree 树上nim
    CodeForces 855E Salazar Slytherin's Locket
    CodeForces 283C World Eater Brothers
  • 原文地址:https://www.cnblogs.com/haw2106/p/10113504.html
Copyright © 2020-2023  润新知