一、如何登录mysql
root@VM-0-2-ubuntu:/home/ubuntu#
root@VM-0-2-ubuntu:/home/ubuntu# mysql -uroot -p
//登录mysql数据库
Enter password:
//输入mysql的密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 305
Server version: 5.7.29-0ubuntu0.18.04.1-log (Ubuntu)
Copyright (c) 2000, 2020, 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>
二、如何查看mysql版本号
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 306
Server version: 5.7.29-0ubuntu0.18.04.1-log (Ubuntu)
Copyright (c) 2000, 2020, 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>
mysql>
mysql> select version();
//注意在数据库中操作命令,最后需要带分号
+-----------------------------+
| version() |
+-----------------------------+
| 5.7.29-0ubuntu0.18.04.1-log |
+-----------------------------+
1 row in set (0.00 sec)
mysql>
三、如何查看mysql是否开启binlog
mysql>
mysql> show variables like "%bin%";
+--------------------------------------------+--------------------------------+
| Variable_name | Value |
+--------------------------------------------+--------------------------------+
| bind_address | 127.0.0.1 |
| binlog_cache_size | 32768 |
| binlog_checksum | CRC32 |
| binlog_direct_non_transactional_updates | OFF |
| binlog_error_action | ABORT_SERVER |
| binlog_format | ROW |
| binlog_group_commit_sync_delay | 0 |
| binlog_group_commit_sync_no_delay_count | 0 |
| binlog_gtid_simple_recovery | ON |
| binlog_max_flush_queue_time | 0 |
| binlog_order_commits | ON |
| binlog_row_image | FULL |
| binlog_rows_query_log_events | OFF |
| binlog_stmt_cache_size | 32768 |
| binlog_transaction_dependency_history_size | 25000 |
| binlog_transaction_dependency_tracking | COMMIT_ORDER |
| innodb_api_enable_binlog | OFF |
| innodb_locks_unsafe_for_binlog | OFF |
| log_bin | ON |
//此行如果是ON,则是已开启。
| log_bin_basename | /var/log/mysql/mysql-bin |
| log_bin_index | /var/log/mysql/mysql-bin.index |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
| log_statements_unsafe_for_binlog | ON |
| max_binlog_cache_size | 18446744073709547520 |
| max_binlog_size | 104857600 |
| max_binlog_stmt_cache_size | 18446744073709547520 |
| sql_log_bin | ON |
| sync_binlog | 1 |
+--------------------------------------------+--------------------------------+
29 rows in set (0.04 sec)
mysql>
四、如何确认ubuntu采用mysql的哪个配置文件
当我们需要修改mysql的配置文件时,需要找到mysql启动时是加载了哪个my.cnf文件。
4.1
查看mysql
指定目录my.cnf文件
查看mysql进程,是否有设置使用指定目录的my.cnf文件,如果有则表示mysql启动时是加载了这个配置文件。如果命令没有输出,表示没有设置使用指定目录的my.cnf。
root@VM-0-2-ubuntu:/home/ubuntu# ps aux|grep mysql|grep 'my.cnf'
4.2 查看mysql默认读取my.cnf目录
如果没有设置使用指定目录的my.cnf,mysql启动时会读取安装目录根目录及默认目录下的my.cnf文件。mysql默认会搜寻my.cnf的目录,顺序排前的优先。
root@VM-0-2-ubuntu:/home/ubuntu# mysql --help|grep 'my.cnf'
4.3 启动时没有使用配置文件
如果没有设置使用指定目录my.cnf文件及默认读取目录没有my.cnf文件,表示mysql启动时并没有加载配置文件,而是使用默认配置。
此时如果需要修改配置,可以在mysql默认读取的目录中,创建一个my.cnf文件,把需要修改的配置内容写入,重启mysql后即可生效。
五、如何在ubuntu下开始、停止、重启mysql
root@VM-0-2-ubuntu:/home/ubuntu# sudo service mysql start
root@VM-0-2-ubuntu:/home/ubuntu# sudo service mysql stop
root@VM-0-2-ubuntu:/home/ubuntu# sudo service mysql restart