合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
# 二进制安装MySQL-5.6.40 ## 0.准备工作-下载mysql ``` https://downloads.mysql.com/archives/community/ mkdir /root/tools -p cd /root/tools wget https://downloads.mysql.com/archives/get/file/mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz ``` ## 1.添加用户 ``` useradd -s /sbin/nologin -M mysql ``` ## 2.解压 mysql 二进制包 ``` cd /root/tools tar xf mysql-5.6.40-*-x86_64.tar.gz ``` <!--more--> ## 3.把MySQL 移动到 /apps/ ``` mkdir -p /apps/ mv /root/tools/mysql-5.6.40-*-x86_64 /apps/mysql-5.6.40 ``` ## 4.创建软连接 ``` ln -s /apps/mysql-5.6.40/ /apps/mysql ``` ## 5.让MySQL用户管理 /apps/mysql ``` chown -R mysql.mysql /apps/mysql/data ``` ## 6.安装这个软件 初始化数据库 > #1.软件安装在哪里 > #2.数据存放在哪里 > #3.MySQL使用的用户谁? ``` /apps/mysql/scripts/mysql_install_db --basedir=/apps/mysql --datadir=/apps/mysql/data --user=mysql ``` ``` #####To start mysqld at boot time you have to copy #####support-files/mysql.server to the right place for your system #####mysql启动脚本 默认放在support-files/mysql.server ##### #####记得给MySQL设置个密码 #####PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! #####To do so, start the server, then issue the following commands: ##### ##### /apps/mysql/bin/mysqladmin -u root password 'new-password' ##### /apps/mysql/bin/mysqladmin -u root -h web01 password 'new-password' ``` ## 7.复制启动脚本 授权 ``` cp /apps/mysql/support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld ``` ## 8.修改启动脚本 和 mysql命令 中的路径 ``` sed -i 's#/usr/local/mysql#/apps/mysql#g' /apps/mysql/bin/mysqld_safe /etc/init.d/mysqld ``` ## 9.复制 默认的配置文件 ``` \cp /apps/mysql/support-files/my-default.cnf /etc/my.cnf /etc/init.d/mysqld start ``` ``` ###故障 ##1./tmp权限 ##2.主机名解析 hosts解析 #ping 主机名 ##3.一步一步执行 ## ##/apps/mysql/bin/mysql ##Welcome to the MySQL monitor. Commands end with ; or \g. ##Your MySQL connection id is 1 ##Server version: 5.5.49 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> ``` ## 10.PATH路径 ``` echo 'export PATH=/apps/mysql/bin:$PATH' >>/etc/profile source /etc/profile which mysql ``` ## 11.加入开机自启动 ``` chkconfig --add mysqld chkconfig mysqld on chkconfig | grep mysql ``` ## 12.给MySQL root用户设置密码 ``` /apps/mysql/bin/mysqladmin -u root password 'oldboy123' ``` ## 13.重新登录MySQL数据库 ``` mysql -uroot -poldboy123 ``` ## 14.数据库基础框架 - #1.数据库 test mysql - #2.表格 ``` #mysql SQL语句 #查看系统中所有数据库 #show databases; #查看系统中所有的用户 #使用某一个数据库 ``` ``` mysql> #查看当前都有啥 mysql> show databases; //******** +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.07 sec) ``` ## 初级 查看系列-开始 ``` ##使用某一个数据库 ###相当于进入 mysql 数据库中 cd mysql ; cd test #use mysql ``` ``` ##我想查看当前在哪? pwd 当前正在使用哪个数据库 select database(); +------------+ | database() | +------------+ | mysql | +------------+ 1 row in set (0.00 sec) ``` ``` ##我是谁? 查看当前用户 select user(); +----------------+ | user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec) ``` ``` ###当前系统都有什么用户? 他们可以在哪里登录? ***** select user,host from mysql.user; +------+-----------+ | user | host | +------+-----------+ | root | 127.0.0.1 | | root | ::1 | | | localhost | | root | localhost | | | web01 | | root | web01 | +------+-----------+ 6 rows in set (0.02 sec) ####初级 查看系列-结束 ###show databases; ###select user,host from mysql.user; ``` ## 初级 添加删除系列 ``` #创建数据库 create database wordpress; #删除数据库 drop database wordpress; #添加用户 grant all on wordpress.* to 'wordpress'@'172.16.1.0/255.255.255.0' identified by '123456'; grant all on wordpress.* to 'wordpress'@'172.16.1.0/255.255.255.0' identified by '123456'; 授权所有的权限, wordpress数据库所有的权限 给 wordpress用户 可以在172.16.1.0/255.255.255.0 网段登录数据库 这个用户的密码123456; #更新系统的权限表 flush privileges; ###进行测试 mysql -uwordpress -p123456 mysql -uwordpress -p -h 172.16.1.8 #删除用户 drop user wordpress@'172.16.1.8'; ``` > ###1.查看都有什么数据库 > ###2.查看都有什么用户 > ###3.添加用户 ## help sql语句。 ``` #跳过授权表(不用密码登录) #/etc/init.d/mysqld restart --skip-grant-table #mysql 命令行 #-u 指定用户 #-p 指定密码(不要有空格) #-h 连接到某一台服务器 #更改密码 mysqladmin -uroot -poldboy123 password '新的密码' ```