加载中...
mysql install mysql 8
发表于:2024-01-10 | 分类: MySQL
字数统计: 11k | 阅读时长: 10 mins.分钟 | 阅读量:

源吗install mysql

cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql10 \
-DMYSQL_DATADIR=/usr/local/data \
-DMYSQLX_UNIX_ADDR=/usr/local/data \
-DWITH_BOOST=/usr/local/mysql5/boost \
-DWITH_SSL=system  \
-DFORCE_INSOURCE_BUILD=1



-DCMAKE_INSTALL_PREFIX #安装路径
-DMYSQL_DATADIR #数据目录
-DMYSQLX_UNIX_ADDR  #mysql.sock

make 
make install

创建用户和组

# groupadd mysql
#  useradd -r -g mysql -s /bin/false mysql

修改权限

[root@bogon ~]# chown  mysql:mysql  /usr/local/mysql10   -R 

初始化数据库

[root@bogon mysql10]# bin/mysqld --initialize --user=mysql
2023-12-12T01:53:46.576032Z 0 [System] [MY-013169] [Server] /usr/local/mysql10/bin/mysqld (mysqld 8.0.35) initializing of server in progress as process 37749
2023-12-12T01:53:46.606977Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-12-12T01:53:47.331431Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-12-12T01:53:48.712559Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: XV)P8ABuXehT

启动数据库

[root@bogon mysql10]# bin/mysqld_safe  --user=mysql & 
& #后台运行服务


为了方便维护数据库
把mysql的启动脚本拷贝到/etc/init.d/下

[root@bogon mysql10]# cp support-files/mysql.server  /etc/init.d/

[root@bogon mysql10]# /etc/init.d/mysql.server  start
Starting MySQL. SUCCESS!
#查看运行状态
[root@bogon mysql10]# ss -lutnp | grep mysql
tcp   LISTEN 0      70                 *:33060            *:*    users:(("mysqld",pid=38748,fd=20))
tcp   LISTEN 0      151                *:3306             *:*    users:(("mysqld",pid=38748,fd=21))

客户端连接

linux 客户端
>  mysql 命令
#本服务器上测试
dnf -y install mysql
windows 客户端
mac 客户端
![navicat](https://navicat.com.cn/)

更新始化密码

[root@bogon mysql10]# 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.35

选项: 
-u #指定用户
-p #指定密码  

更新密码
mysql> alter  user 'root'@'localhost' identified by 'Root@123123';
Query OK, 0 rows affected (0.00 sec)

## 错误信息

  1. 如果客户端在连接的时候出现以下错误信息
[root@bogon ~]# mysql  -uroot -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

解决方法: 在本机查找是否有mysql.sock,如果有可以直接复制或者软链接

[root@bogon ~]# mkdir  /var/lib/mysql
[root@bogon ~]# ln -s  /tmp/mysql.sock  /var/lib/mysql/mysql.sock

MySQL 的基本语法

SQL 语句
增\删\改\查

数据库的基本操作

SQL语句规范

使用sql语句,需要使用关键字大写

获取SQL语句的帮助

mysql> ? show
  1. 查看所有库
mysql> show databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

2.查看创建库的基本信息

语法:`SHOW CREATE DATABASE db_name`
示例
mysql> show  create database mysql;
+----------+---------------------------------------------------------------------------------------------------------------------------------+
| Database | Create Database                                                                                                                 |
+----------+---------------------------------------------------------------------------------------------------------------------------------+
| mysql    | CREATE DATABASE `mysql` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */ |
+----------+---------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
  1. 创建库
语法:`create database db_name `
示例:
mysql> create database y37;
Query OK, 1 row affected (0.01 sec)
  1. 删除库
语法: `drop [datbase|table] db_name`

mysql> drop database  y37;
Query OK, 0 rows affected (0.01 sec) 
  1. 使用库
    语法: use db_name;
    mysql> use suibian
    Database changed

表的操作

  1. 创建表(table)
语法:create table tb_name;

mysql> create table  tb(id int);
Query OK, 0 rows affected (0.01 sec)

mysql> create table  tb1(id int,name char);
Query OK, 0 rows affected (0.01 sec)

<font color=bleen>创建表的时候:指定字段的数据类型</font>
  1. 查看表
mysql> show tables;
+-------------------+
| Tables_in_suibian |
+-------------------+
| tb                |
+-------------------+
1 row in set (0.00 sec)
  1. 查看表结构
语法:desc tb_name
示例:
mysql> desc tb;
+-------+------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------+------+-----+---------+-------+
| id    | int  | YES  |     | NULL    |       |
+-------+------+------+-----+---------+-------+
1 row in set (0.00 sec)
  1. 删除表
语法:DROP TABLE tb_name
mysql> drop table tb1;
Query OK, 0 rows affected (0.00 sec)

修改配置文件客户端显示登录数据库的地址及所在库

vim /etc/my.cnf
[mysql]
prompt=\\U [\\d]>
上一篇:
mysql Data_type
下一篇:
SQL 基础语法
本文目录
本文目录