Apply MySQL notes-manage MySQL services

Source: Internet
Author: User
Tags chmod mysql login mysql view sqlplus

-dsysconfdir=/mysql/conf \ So build the My.cnf file under Conf

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= (\[email protected]\h) [\d]>\
Default-character-set=gbk

Initialize MySQL database:
$/mysql/scripts/mysql_install_db--datadir=/mysql/data--basedir=/mysql

Support-files/mysql.server script start MySQL is not recommended, it is recommended to use Mysqld_safe boot:
$ mysqld_safe--DEFAULTS-FILE=/MYSQL/CONF/MY.CNF &
NETSTAT-LNT |grep 3306
Ps-ef |grep MySQL view MySQL port and process

Configure MySQL
mysql5.6 default root user does not set a password for direct typing mysql login.
Enhanced Security:
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 Users, two users do not have a user name. So you can log in directly via MySQL.
The following retains a root user for all other users to delete.
Modify the root user name
Update Mysql.user set user= ' System ', Password=password (' Oralinux ');
([email protected]) [(None)]>select * from Mysql.db \g
TRUNCATE TABLE mysql.db;

[Email protected]) [(None)]>exit
Bye
[[email protected] mysql]$ MySQL
ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:no)
[Email protected] mysql]$ mysql-uroot-p ' Oralinux '
Warning:using a password on the command line interface can is insecure.
ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:yes)
[Email protected] mysql]$ mysql-usystem-p ' Oralinux '
Warning:using a password on the command line interface can is 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), Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.

([email protected]) [(None)]>

Create an administrative script to create an intermediate definition file that is designed to improve the reusability of the script:
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
Create a mysql_db_startup.sh script to start the MySQL service:
#!/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 &

$ 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
Create a sqlplus.sh script for quick login:
$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
chmod +x/mysql/scripts/sqlplus.sh
edit the MySQL user variable and add the above path to path
echo "Export path=/mysql/scripts:\ $PATH" >> ~/.bash_profile
SOURCE ~/.bash_profile
set boot up: under 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
The execute sudo command encountered the following error:
Sudo:sorry,you must has a TTY to run sudo
Vi/etc/sudoers comment out 56 lines
#Defaultsrequiretty

Apply MySQL notes-manage MySQL services

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.