搜索看看
CentOS yum安装自带的MySQL 8
1、安装mysql-server
[root@vultr ~]# yum -y install mysql-server Last metadata expiration check: 0:06:55 ago on Mon 27 Mar 2023 11:05:22 AM UTC. Dependencies resolved. ============================================================================================================================================================= Package Architecture Version Repository Size ============================================================================================================================================================= Installing: mysql-server x86_64 8.0.26-1.module_el8.4.0+915+de215114 appstream 25 M Installing dependencies: mariadb-connector-c-config noarch 3.1.11-2.el8_3 appstream 15 k mecab x86_64 0.996-1.module_el8.4.0+589+11e12751.9 appstream 393 k mysql x86_64 8.0.26-1.module_el8.4.0+915+de215114 appstream 12 M mysql-common x86_64 8.0.26-1.module_el8.4.0+915+de215114 appstream 134 k mysql-errmsg x86_64 8.0.26-1.module_el8.4.0+915+de215114 appstream 598 k protobuf-lite x86_64 3.5.0-15.el8 appstream 149 k Enabling module streams: mysql 8.0 ...... ......
2、启动mysql服务并设置为开机启动
[root@vultr ~]# systemctl enable --now mysqld Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service. [root@vultr ~]# systemctl status mysqld ● mysqld.service - MySQL 8.0 database server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2023-03-27 11:14:26 UTC; 10s ago Process: 12014 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS) Process: 11890 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS) Process: 11866 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS) Main PID: 11970 (mysqld) Status: "Server is operational" Tasks: 38 (limit: 5940) Memory: 472.3M CGroup: /system.slice/mysqld.service └─11970 /usr/libexec/mysqld --basedir=/usr Mar 27 11:14:19 vultr.guest systemd[1]: Starting MySQL 8.0 database server... Mar 27 11:14:19 vultr.guest mysql-prepare-db-dir[11890]: Initializing MySQL database Mar 27 11:14:26 vultr.guest systemd[1]: Started MySQL 8.0 database server.
3、修改mysql的密码,这里修改为123456
[root@vultr ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.26 Source distribution 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.01 sec) 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> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> exit Bye [root@vultr ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.0.26 Source distribution 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> exit; Bye [root@vultr ~]#
好了,至此MySQL就安装好了,默认端口是3306