From 71102302217bd721c5591b9162b5451bfd9bd0fe Mon Sep 17 00:00:00 2001 From: 8ga Date: Fri, 10 Jan 2025 11:11:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20ubuntu-mysql5.7.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ubuntu-mysql5.7.md | 177 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 ubuntu-mysql5.7.md diff --git a/ubuntu-mysql5.7.md b/ubuntu-mysql5.7.md new file mode 100644 index 0000000..774f096 --- /dev/null +++ b/ubuntu-mysql5.7.md @@ -0,0 +1,177 @@ +切换目录 +``` +cd /usr/local +``` + +浏览器打开 https://dev.mysql.com/downloads/mysql/5.7.html#downloads 选择配置然后下载 + +- Archives +- 5.7.44 +- Linux - Generic +- 64-bit +- Compressed TAR Archive + +浏览器建立下载任务后,复制下载链接,回到命令行通过命令下载解压 + +``` +wget 下载链接 +``` +``` +tar -zvxf mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz +``` +``` +mv mysql-5.7.44-linux-glibc2.12-x86_64 /usr/local/mysql +``` +``` +cd /usr/local/mysql +``` + +创建必要的目录 + +``` +mkdir data +``` +``` +mkdir tmp +``` +``` +mkdir run +``` +``` +mkdir log +``` + +创建必要的文件 +``` +cd run +``` +``` +touch mysql.sock +``` +``` +touch mysql.pid +``` + +编辑配置文件 +``` +vim /etc/my.cnf +``` + +复制粘贴以下内容 +``` +[client] +port = 24100 +socket = /usr/local/mysql/run/mysql.sock +[mysqld] +user = root +server-id = 1 +port = 24100 +basedir = /usr/local/mysql +datadir = /usr/local/mysql/data +tmpdir = /usr/local/mysql/tmp +socket = /usr/local/mysql/run/mysql.sock +pid-file = /usr/local/mysql/run/mysql.pid +character-set-server = utf8mb4 +collation-server = utf8mb4_general_ci +init_connect='SET NAMES utf8mb4' +lower_case_table_names = 1 +max_connections = 400 +max_connect_errors = 1000 +explicit_defaults_for_timestamp = true +max_allowed_packet = 128M +interactive_timeout = 1800 +wait_timeout = 1800 +tmp_table_size = 16M +max_heap_table_size = 128M +query_cache_size = 0 +query_cache_type = 0 +read_buffer_size = 2M +read_rnd_buffer_size = 8M +sort_buffer_size = 8M +binlog_cache_size = 1M +back_log = 130 +log_error = /usr/local/mysql/log/error.log +slow_query_log = 1 +long_query_time = 5 +slow_query_log_file = /usr/local/mysql/log/slow.log +log_throttle_queries_not_using_indexes = 0 +min_examined_row_limit = 100 +expire_logs_days = 5 +log-bin = mysql-bin +binlog_format = ROW +binlog_row_image = minimal +innodb_open_files = 300 +innodb_buffer_pool_size = 512M +innodb_log_buffer_size = 2M +innodb_flush_method = O_DIRECT +innodb_write_io_threads = 4 +innodb_read_io_threads = 4 +innodb_lock_wait_timeout = 60 +innodb_log_file_size = 32M +sql_mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_IN_DATE,NO_ZERO_DATE +``` + +初始化mysql +``` +cd /usr/local/mysql/bin +``` +``` +./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=root --initialize +``` + +查看默认密码 +``` +cat /usr/local/mysql/log/error.log +``` + +找到这一行,截图或者复制粘贴出来等下要用 +``` +[Note] A temporary password is generated for root@localhost: xxxxxx +``` + +运行mysql +``` +cd /usr/local/mysql/support-files +``` +``` +./mysql.server start +``` + +命令行连接mysql +``` +cd /usr/local/mysql/bin +``` + +密码是前面看到的默认密码 +``` +./mysql -u root -p +``` + +修改root账号的默认密码 + +``` +SET PASSWORD = PASSWORD('填写明文密码'); +``` +``` +ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; +``` + +刷新 +``` +FLUSH PRIVILEGES; +``` + +添加用户 +``` +CREATE USER '用户名'@'%' IDENTIFIED BY '填写明文密码'; +``` + +建库 +``` +CREATE DATABASE `库名`; +``` + +授权(不要忘记刷新) +``` +GRANT ALL ON 库名.* TO '用户名'@'%'; +``` \ No newline at end of file