安装 MySQL 8.0
Ubuntu 18.04
下载镜像源
https://dev.mysql.com/get/mysql-apt-config_0.8.15-1_all.deb
安装MySQL 8.0镜像源
dpkg -i mysql-apt-config_0.8.15-1_all.deb
会弹出一个界面, 请在界面中选中要安装的是 MySQL 8.0 !!!
更新镜像源
sudo apt update
安装 MySQL 8.0
如果你之前安装过其他版本的MySQL, 那么在安装 MySQL8.0 的前会自动卸载掉其他版本, 请注意保存数据
sudo apt install mysql-server
配置远程访问
打开MySQL命令行
mysql
root@jansora-Vostro-3669:~# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.22-0ubuntu0.20.04.3 (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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.04 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Query OK, 0 rows affected (0.06 sec)
mysql> update user set host='%' where user ='root';
Query OK, 1 row affected (0.12 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.04 sec)
配置远程访问
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.14 sec)
调整配置项 vim /etc/mysql/mysql.conf.d/mysqld.cnf
#bind-address = 127.0.0.1
bind-address = 0.0.0.0
重启 MySQL systemctl restart mysql
docker 安装 MySQL 5.0
1. 拉取镜像
docker pull mysql/mysql-server:5.7
2. 启动镜像
docker run -p 3307:3306 --name mysql57 -d mysql/mysql-server:5.7
3. 检索密码
docker logs mysql57
[Entrypoint] GENERATED ROOT PASSWORD: 7_58t5t=g@H6^@ceg97@EIRQIy:&Vni8
所有日志
[Entrypoint] No password option specified for new database.
[Entrypoint] A random onetime password will be generated.
2021-06-11T02:33:44.658273Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-06-11T02:33:45.059722Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-06-11T02:33:45.079785Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-06-11T02:33:45.083041Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 718df609-ca5d-11eb-9431-0242ac110002.
2021-06-11T02:33:45.083670Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-06-11T02:33:45.230884Z 0 [Warning] CA certificate ca.pem is self signed.
2021-06-11T02:33:45.308302Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2021-06-11T02:33:47.118959Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-06-11T02:33:47.119831Z 0 [Note] mysqld (mysqld 5.7.34) starting as process 50 ...
2021-06-11T02:33:47.122023Z 0 [Note] InnoDB: PUNCH HOLE support available
2021-06-11T02:33:47.122054Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-06-11T02:33:47.122058Z 0 [Note] InnoDB: Uses event mutexes
2021-06-11T02:33:47.122061Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2021-06-11T02:33:47.122063Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-06-11T02:33:47.122064Z 0 [Note] InnoDB: Using Linux native AIO
2021-06-11T02:33:47.122191Z 0 [Note] InnoDB: Number of pools: 1
2021-06-11T02:33:47.122271Z 0 [Note] InnoDB: Using CPU crc32 instructions
2021-06-11T02:33:47.123087Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2021-06-11T02:33:47.127652Z 0 [Note] InnoDB: Completed initialization of buffer pool
2021-06-11T02:33:47.129604Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-06-11T02:33:47.141170Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2021-06-11T02:33:47.146278Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2021-06-11T02:33:47.146355Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2021-06-11T02:33:47.159547Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2021-06-11T02:33:47.160031Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2021-06-11T02:33:47.160053Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2021-06-11T02:33:47.160777Z 0 [Note] InnoDB: 5.7.34 started; log sequence number 2747334
2021-06-11T02:33:47.160912Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2021-06-11T02:33:47.161030Z 0 [Note] Plugin 'FEDERATED' is disabled.
2021-06-11T02:33:47.161949Z 0 [Note] InnoDB: Buffer pool(s) load completed at 210611 2:33:47
2021-06-11T02:33:47.164326Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2021-06-11T02:33:47.164347Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2021-06-11T02:33:47.164737Z 0 [Warning] CA certificate ca.pem is self signed.
2021-06-11T02:33:47.164783Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2021-06-11T02:33:47.170240Z 0 [Note] Event Scheduler: Loaded 0 events
2021-06-11T02:33:47.170420Z 0 [Note] mysqld: ready for connections.
Version: '5.7.34' socket: '/var/lib/mysql/mysql.sock' port: 0 MySQL Community Server (GPL)
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2021-06-11T02:33:48.929228Z 0 [Note] Giving 0 client threads a chance to die gracefully
2021-06-11T02:33:48.929328Z 0 [Note] Shutting down slave threads
2021-06-11T02:33:48.929341Z 0 [Note] Forcefully disconnecting 0 remaining clients
2021-06-11T02:33:48.929351Z 0 [Note] Event Scheduler: Purging the queue. 0 events
2021-06-11T02:33:48.929491Z 0 [Note] Binlog end
2021-06-11T02:33:48.930824Z 0 [Note] Shutting down plugin 'ngram'
2021-06-11T02:33:48.930852Z 0 [Note] Shutting down plugin 'partition'
2021-06-11T02:33:48.930856Z 0 [Note] Shutting down plugin 'BLACKHOLE'
2021-06-11T02:33:48.930858Z 0 [Note] Shutting down plugin 'ARCHIVE'
2021-06-11T02:33:48.930859Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
[Entrypoint] GENERATED ROOT PASSWORD: 7_58t5t=g@H6^@ceg97@EIRQIy:&Vni8
2021-06-11T02:33:48.930882Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
2021-06-11T02:33:48.930883Z 0 [Note] Shutting down plugin 'MyISAM'
2021-06-11T02:33:48.930890Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
2021-06-11T02:33:48.930892Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2021-06-11T02:33:48.930893Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2021-06-11T02:33:48.930894Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2021-06-11T02:33:48.930895Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2021-06-11T02:33:48.930896Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2021-06-11T02:33:48.930897Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2021-06-11T02:33:48.930897Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2021-06-11T02:33:48.930898Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2021-06-11T02:33:48.930899Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2021-06-11T02:33:48.930901Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2021-06-11T02:33:48.930902Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2021-06-11T02:33:48.930903Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2021-06-11T02:33:48.930903Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2021-06-11T02:33:48.930904Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2021-06-11T02:33:48.930905Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2021-06-11T02:33:48.930906Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
2021-06-11T02:33:48.930907Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
2021-06-11T02:33:48.930908Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2021-06-11T02:33:48.930909Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2021-06-11T02:33:48.930909Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2021-06-11T02:33:48.930910Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2021-06-11T02:33:48.930911Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2021-06-11T02:33:48.930912Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2021-06-11T02:33:48.930913Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
2021-06-11T02:33:48.930913Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2021-06-11T02:33:48.930914Z 0 [Note] Shutting down plugin 'INNODB_CMP'
2021-06-11T02:33:48.930915Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2021-06-11T02:33:48.930916Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
2021-06-11T02:33:48.930916Z 0 [Note] Shutting down plugin 'INNODB_TRX'
2021-06-11T02:33:48.930917Z 0 [Note] Shutting down plugin 'InnoDB'
2021-06-11T02:33:48.931023Z 0 [Note] InnoDB: FTS optimize thread exiting.
2021-06-11T02:33:48.931179Z 0 [Note] InnoDB: Starting shutdown...
2021-06-11T02:33:49.031433Z 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
2021-06-11T02:33:49.031800Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 210611 2:33:49
2021-06-11T02:33:50.023581Z 0 [Note] InnoDB: Shutdown completed; log sequence number 12120546
2021-06-11T02:33:50.026359Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2021-06-11T02:33:50.026409Z 0 [Note] Shutting down plugin 'MEMORY'
2021-06-11T02:33:50.026414Z 0 [Note] Shutting down plugin 'CSV'
2021-06-11T02:33:50.026417Z 0 [Note] Shutting down plugin 'sha256_password'
2021-06-11T02:33:50.026418Z 0 [Note] Shutting down plugin 'mysql_native_password'
2021-06-11T02:33:50.026508Z 0 [Note] Shutting down plugin 'binlog'
2021-06-11T02:33:50.028932Z 0 [Note] mysqld: Shutdown complete
2021-06-11T02:33:51.076896Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-06-11T02:33:51.077689Z 0 [Note] mysqld (mysqld 5.7.34) starting as process 1 ...
2021-06-11T02:33:51.079732Z 0 [Note] InnoDB: PUNCH HOLE support available
2021-06-11T02:33:51.079758Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-06-11T02:33:51.079762Z 0 [Note] InnoDB: Uses event mutexes
2021-06-11T02:33:51.079763Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2021-06-11T02:33:51.079767Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-06-11T02:33:51.079768Z 0 [Note] InnoDB: Using Linux native AIO
2021-06-11T02:33:51.079893Z 0 [Note] InnoDB: Number of pools: 1
2021-06-11T02:33:51.079978Z 0 [Note] InnoDB: Using CPU crc32 instructions
2021-06-11T02:33:51.080768Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2021-06-11T02:33:51.084863Z 0 [Note] InnoDB: Completed initialization of buffer pool
2021-06-11T02:33:51.086076Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-06-11T02:33:51.097225Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2021-06-11T02:33:51.101803Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2021-06-11T02:33:51.101851Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2021-06-11T02:33:51.113917Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2021-06-11T02:33:51.114391Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2021-06-11T02:33:51.114413Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2021-06-11T02:33:51.114779Z 0 [Note] InnoDB: 5.7.34 started; log sequence number 12120546
2021-06-11T02:33:51.114891Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2021-06-11T02:33:51.115027Z 0 [Note] Plugin 'FEDERATED' is disabled.
2021-06-11T02:33:51.116737Z 0 [Note] InnoDB: Buffer pool(s) load completed at 210611 2:33:51
2021-06-11T02:33:51.118239Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2021-06-11T02:33:51.118259Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2021-06-11T02:33:51.118659Z 0 [Warning] CA certificate ca.pem is self signed.
2021-06-11T02:33:51.118702Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2021-06-11T02:33:51.118872Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2021-06-11T02:33:51.118915Z 0 [Note] IPv6 is available.
2021-06-11T02:33:51.118923Z 0 [Note] - '::' resolves to '::';
2021-06-11T02:33:51.118931Z 0 [Note] Server socket created on IP: '::'.
2021-06-11T02:33:51.124555Z 0 [Note] Event Scheduler: Loaded 0 events
2021-06-11T02:33:51.124782Z 0 [Note] Execution of init_file '/var/lib/mysql-files/XU93MaoLj3' started.
2021-06-11T02:33:51.125189Z 0 [Note] Execution of init_file '/var/lib/mysql-files/XU93MaoLj3' ended.
2021-06-11T02:33:51.125257Z 0 [Note] mysqld: ready for connections.
Version: '5.7.34' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL)
进入容器
docker exec -it mysql57 bash
登录 MYSQL
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
bash-4.2# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.34
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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> set password=password("12345678")
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '12345678' WITH GRANT OPTION;;