[root@localhost ~]# mysql -u root -p Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
1、查看mysql服务是否在运行:
端口是否打开 lsof -i:3306
1
[root@localhost ~]# lsof -i:3306
2.mysqld服务是否正在运行service mysqld status
1 2
[root@localhost ~]# service mysqld status ERROR! MySQL is not running
3.启动mysqlservice mysql start
1 2 3 4 5 6 7 8 9 10 11 12
[root@localhost ~]# service mysql start Starting MySQL.. SUCCESS!
//查看状态 [root@localhost ~]# service mysqld status SUCCESS! MySQL running (4571) //看mysql服务是否在运行 [root@localhost ~]# lsof -i:3306 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 4571 mysql 23u IPv6 50765 0t0 TCP *:mysql (LISTEN)
[mysql] # 客户端默认字符集 default-character-set=utf8mb4 [client] port=3306 socket=/var/lib/mysql/mysql.sock [mysqld] port=3306 server-id=3306 user=mysql datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # 设置mysql的安装目录 basedir=/usr/local/mysql8.0.25 #自己的安装路径 # 设置mysql数据库的数据的存放目录 datadir=/data/mysqldata/mysql #你自己创建的数据库文件存放路径 log-bin=/data/mysqldata/mysql/mysql-bin innodb_data_home_dir=/data/mysqldata/mysql innodb_log_group_home_dir=/data/mysqldata/mysql character-set-server=utf8mb4 lower_case_table_names=1 autocommit=1 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd
[root@localhost local]# cd /usr/local/mysql8.0.25/bin/ [root@localhost bin]# ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql8.0.25/ --datadir=/data/mysqldata/mysql --user=mysql --initialize 2021-09-27T07:47:49.269631Z 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. 2021-09-27T07:47:49.270101Z 0 [System] [MY-013169] [Server] /usr/local/mysql8.0.25/bin/mysqld (mysqld 8.0.25) initializing of server in progress as process 70235 2021-09-27T07:47:49.301585Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2021-09-27T07:47:50.139914Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2021-09-27T07:47:51.785857Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: g/zf(ay.s13Z
//启动mysql [root@localhost bin]# service mysql start
启动成功
1 2
Starting MySQL.Logging to '/data/mysqldata/mysql/mysql.log'. . SUCCESS!
mysql数据库设置
登录mysql ,修改初始密码
1 2 3 4 5 6 7
mysql -u root -p 或 #进入安装目录 cd /home/mysql-8.0.25/bin # 执行命令 ./mysql -uroot -p 输入临时密码
1 2 3 4 5 6 7 8 9 10 11 12 13
[root@localhost bin]# ./mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.25
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.
1 2 3 4 5 6 7 8 9 10
# 修改root密码 修改root用户只能本地连接 ALTER USER 'root'@'localhost' IDENTIFIED with mysql_native_password BY '新密码'; #刷新权限 flush privileges;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED with mysql_native_password BY 'root'; Query OK, 0 rows affected (0.00 sec)