[root@ss-1 mysql]# ./bin/mysqld --initialize --user=mysql./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory#如果出现上面的报错,就是缺少 libaio 库,执行下面的命令安装上即可。[root@ss-1 mysql]# yum install libaio -y[root@ss-1 mysql]# ./bin/mysqld --initialize --user=mysql2022-09-13T05:31:27.610325Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.2022-09-13T05:31:27.610559Z 0 [System] [MY-013169] [Server] /root/workspace_mysql/mysql-8.0.28-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.28) initializing of server in progress as process 210062022-09-13T05:31:27.633452Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.2022-09-13T05:31:29.433746Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.2022-09-13T05:31:31.144844Z 0 [Warning] [MY-013829] [Server] Missing data directory for ICU regular expressions: /root/workspace_mysql/mysql-8.0.28-linux-glibc2.12-x86_64/lib/private/.2022-09-13T05:31:32.473696Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: kIg=+&Kn7Bya6. 开启ssl
[root@ss-1 tmp]# mysql -h 127.0.0.1 -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 12Server version: 8.0.28Copyright (c) 2000, 2022, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> mysql> 可以看到,数据库连接已经没问题了。
三、修改 root 密码
虽然 mysql 数据库已经能连接了,但还没结束,当我们执行 show databases; 时,会提示如下错误:
mysql> show databases;ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.意思是提醒咱们不要用初始密码,这是需要修改密码:
mysql> alter user user() identified by '123456';Query OK, 0 rows affected (0.03 sec)mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sys |+--------------------+4 rows in set (0.01 sec)mysql> 修改完密码之后,可以看到错误就消失了。
四、创建 'root'@'%' 用户
初始 root@localhost 用户是无法远程登录的,要远程登录,咱们还需要创建 root@%用户。
create user 'root'@'%' identified by '123456';grant all on *.* to 'root'@'%';flush privileges;