涂抹mysql笔记-管理mysql服务
-DSYSCONFDIR=/mysql/conf \ 所以在conf下建立my.cnf文件
vi my.cnf
[client]
port=3306
socket=/mysql/conf/mysql.sock
#The MySQL server
[mysqld]
port=3306
user=mysql
socket=/mysql/conf/mysql.sock
pid-file=/mysql/conf/mysql.pid
basedir=/mysql
datadir=/mysql/data
tmpdir=/mysql/tmp
open_files_limit=10240
explicit_defaults_for_timestamp
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#Buffer
max_allowed_packet=256M
max_heap_table_size=256M
net_buffer_length=8k
sort_buffer_size=2M
join_buffer_size=4M
read_buffer_size=2M
read_rnd_buffer_size=16M
#log
log-bin=/mysql/binlog/mysql-bin
binlog_cache_size=32M
max_binlog_cache_size=512M
max_binlog_size=512M
binlog_format=mixed
log_output=FILE
log-error=/mysql/logs/mysql-error.log
slow_query_log=1
slow_query_log_file=/mysql/logs/slow_query.log
general_log=0
general_log_file=/mysql/logs/general_query.log
expire-logs-days=14
#InnoDB
innodb_data_file_path=ibdata1:2048M:autoextend
innodb_log_file_size=256M
innodb_log_files_in_group=3
innodb_buffer_pool_size=1024M
[mysql]
no-auto-rehash
prompt=(\u@\h) [\d]>\
default-character-set=gbk
初始化mysql数据库:
$ /mysql/scripts/mysql_install_db --datadir=/mysql/data --basedir=/mysql
启动mysql数据库
support-files/mysql.server脚本启动mysql不推荐,推荐使用mysqld_safe启动:
$ mysqld_safe --defaults-file=/mysql/conf/my.cnf &
netstat -lnt |grep 3306
ps -ef |grep mysql 查看mysql端口和进程
配置mysql
mysql5.6默认root用户不设密码的直接敲入mysql登录。
增强安全性:
select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| | linux01 |
| root | linux01 |
| | localhost |
| root | localhost |
+------+-----------+
6 rows in set (0.01 sec)
6个用户,两个用户没有用户名。所以直接可通过mysql登录。
下面保留一条root用户其他用户全部删除。
delete from mysql.user where (user,host) not in (select 'root','localhost');
修改root用户名
update mysql.user set user='system',password=password('oralinux');
(root@localhost) [(none)]>select * from mysql.db \G
(root@localhost) [(none)]>truncate table mysql.db;
(root@localhost) [(none)]>flush privileges;
root@localhost) [(none)]>exit
Bye
[mysql@linux01 mysql]$ mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[mysql@linux01 mysql]$ mysql -uroot -p'oralinux'
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[mysql@linux01 mysql]$ mysql -usystem -p'oralinux'
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.34-log JASON
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.
(system@localhost) [(none)]>
创建管理脚本,创建中间定义文件,目的是提高脚本的复用性:
vi /mysql/scripts/mysql_env.ini
#set env
MYSQL_USER=system
MYSQL_PASS='oralinux'
#check parameter
if [ $# -ne 1 ]
then
HOST_PORT=3306
else
HOST_PORT=$1
fi
$ chmod 600 /mysql/scripts/mysql_env.ini
创建mysql_db_startup.sh脚本,用于启动mysql服务:
#!/bin/sh
# Created by jason
source /mysql/scripts/mysql_env.ini
echo "Startup MySQL Service:localhost_"${HOST_PORT}
/mysql/bin/mysqld_safe --defaults-file=/mysql/conf/my.cnf &
创建mysql_db_shutdown.sh脚本,用于关闭mysql服务:
$ vi /mysql/scripts/mysql_db_shutdown.sh
#!/bin/sh
#Created by jason
source /mysql/scripts/mysql_env.ini
echo "Shutdown MySQL Service:localhost_"${HOST_PORT}
/mysql/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PASS} -S /mysql/conf/mysql.sock shutdown
创建sqlplus.sh脚本用于快速登录:
$vi /mysql/scripts/sqlplus.sh
#!/bin/sh
#Created by jason
source /mysql/scripts/mysql_env.ini
echo "Login MySQL Service:localhost_"${HOST_PORT}
/mysql/bin/mysql -u${MYSQL_USER} -p${MYSQL_PASS} -S /mysql/conf/mysql.sock $2
chmod +x /mysql/scripts/sqlplus.sh
编辑mysql用户变量,将上述路径加入到PATH中
echo "export PATH=/mysql/scripts:\$PATH" >> ~/.bash_profile
source ~/.bash_profile
设置开机启动:root下
# vi /etc/rc.localhost
# autostart mysql ,added by jason at 2017-03-31
sudo -i -u mysql /mysql/scripts/mysql_db_startup.sh 3306 > /mysql/logs/mysql_db_startup.log 2>&1
执行sudo命令遇到下列错误:
sudo:sorry,you must have a tty to run sudo
vi /etc/sudoers 注释掉56行
#Defaults requiretty
涂抹mysql笔记-管理mysql服务的更多相关文章
- 涂抹mysql笔记-管理mysql库和表
mysql的表对象是基于库维护的,也就是说它属于某个库,不管对象是由谁创建的,只要库在表就在.这根Oracle不同Oracle中的表对象是基于用户的.属于创建改对象的用户所有,用户在表就在.mysql ...
- MySQL:管理MySQL、事务(三)
干货: 命令行程序mysql实际上是MySQL客户端,真正的MySQL服务器程序是mysqld,在后台运行. 数据库事务具有ACID特性,用来保证多条SQL的全部执行. 五.MySQL 通过mysql ...
- 涂抹mysql笔记-搭建mysql高可用体系
mysql的高可用体系<>追求更高稳定性的服务体系 可扩展性:横向扩展(增加节点).纵向扩展(增加节点的硬件配置) 高可用性<>Slave+LVS+Keepalived实现高可 ...
- 涂抹mysql笔记-安装mysql
1.mysql安装:(1)RPM安装:rpm -ivh xxx 建议安装三个:MySQL-server-VERSION.PLATFORM-cpu.rpmMySQL-client-VERSION.PLA ...
- 【MySQL笔记】mysql来源安装/配置步骤和支持中国gbk/gb2312编码配置
不久的学习笔记.分享.我想有很大的帮助谁刚开始学习其他人的 备注:该票据于mysql-5.1.73版本号例如 1. mysql源代码编译/安装步骤 1) 官网下载mysql源代码并解压 2) cd至源 ...
- MySQL 笔记(Mysql 8.0.16)
用户登陆 mysql -u user_name -p 修改密码 ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; 关闭服务 D:\ ...
- MySQL用户管理+MySQL权限管理
我们现在默认使用的都是root用户,超级管理员,拥有全部的权限! 但是,一个公司里面的数据库服务器上面可能同时运行着很多个项目的数据库! 所以,我们应该可以根据不同的项目建立不同的用户,分配不同的权限 ...
- [MYSQL笔记0]MYSQL的安装
mysql是一种关系型数据库管理系统.以mysql5.7版本为例,安装过程如下: 首先百度出mysql的官网,进入:(以下是自己安装失败的过程,直接下拉最后看大佬的安装过程吧,就是那个红红的网址) 找 ...
- 【MySQL笔记】mysql报错"ERROR 1206 (HY000): The total number of locks exceeds the lock table size"的解决方法
step1:查看 1.1 Mysql命令行里输入"show engines:"查看innoddb数据引擎状态, 1.2 show variables "%_buffer% ...
随机推荐
- 2010-10-08在浏览器中兼容+jQuery3
一.实现背景图片铺满(兼容各种浏览器) <script type="text/javascript"> $(document).ready(function() { $ ...
- wishhack 玩法概览
抢流量玩法 超级店长玩法 https://www.wishhack.com/article/50.html https://www.wishhack.com/article/43.html
- jQuery-----隔行换色/全选全不选/
隔行换色: 全选全不选: 分析: 1.页面加载 $(function(){}) 2.获取所有奇数行数 ...
- 事件驱动模型和异步IO多路复用
事件驱动模型 协程:遇到IO操作就切换. 但什么时候切回去呢?怎么确定IO操作完了? 很多程序员可能会考虑使用“线程池”或“连接池”.“线程池”旨在减少创建和销毁线程的频率,其维持一定合理数量的线程, ...
- Windows10 VS2017 C++ ini解析(使用simpleini头文件)
simpleini项目地址: https://github.com/brofield/simpleini 下载,新建项目,并将SimpleIni.h文件通过包含目录的方式加载进来. 创建test.in ...
- 一条命令将windows下多个ts文件合并为一个ts文件
首先在待合并的文件夹下创建concat.bat(名字随意啦),写入如下命令 copy /b "%~dp0"\*.ts "%~dp0"\new.ts 执行该命令后 ...
- SuSE Linux Enterprise Server - 软件包下载地址
官方地址: https://software.opensuse.org
- Python全栈之路----函数进阶----迭代器
我们已经知道,可以直接作用于 for 循环的数据类型有以下几种: 一类是集合数据类型,如 list , tuple , dict , set ,str 等: 一类是 generator ,包括生成器和 ...
- hdu 1166 (单点更新+区间求和+裸题)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissi ...
- SQL-记录查询篇-009
在学习记录查询之前,学习一些关键字的使用: 1.逻辑运算符:and . or . not .is null select * from table_name where id>2 and ...