【how to connect to mysql from Aliyun ECS cloud server】

发布时间:2023年12月20日

I) connect mysql from Linux OS, create database, create table and retrieve the tables, and show the table structure (CRUD, etc)

[root@iZ2vc5lqzt23aweti4j777Z ~]# ls -tl
total 32
drwxr-xr-x 2 root root  4096 Dec 19 19:52 folder_Dec19th2023
-rw-r--r-- 1 root root 25548 Apr  7  2017 mysql57-community-release-el7-10.noarch.rpm
[root@iZ2vc5lqzt23aweti4j777Z ~]# systemctl start httpd
[root@iZ2vc5lqzt23aweti4j777Z ~]# systemctl enable httpd
[root@iZ2vc5lqzt23aweti4j777Z ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2023-12-19 15:55:01 CST; 4h 56min ago
     Docs: man:httpd.service(8)
 Main PID: 753 (/usr/sbin/httpd)
   Status: "Running, listening on: ::706f:5707:ff7f:0 port 80, ..."
    Tasks: 213 (limit: 11861)
   Memory: 32.8M
   CGroup: /system.slice/httpd.service
           ├─753 /usr/sbin/httpd -DFOREGROUND
           ├─843 /usr/sbin/httpd -DFOREGROUND
           ├─846 /usr/sbin/httpd -DFOREGROUND
           ├─847 /usr/sbin/httpd -DFOREGROUND
           └─848 /usr/sbin/httpd -DFOREGROUND

Dec 19 15:55:00 iZ2vc5lqzt23aweti4j777Z systemd[1]: Starting The Apache HTTP Server...
Dec 19 15:55:01 iZ2vc5lqzt23aweti4j777Z httpd[753]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.23.95.44. Set the '>
Dec 19 15:55:01 iZ2vc5lqzt23aweti4j777Z systemd[1]: Started The Apache HTTP Server.
Dec 19 15:55:01 iZ2vc5lqzt23aweti4j777Z httpd[753]: Server configured, listening on: ::706f:5707:ff7f:0 port 80, ...

[root@iZ2vc5lqzt23aweti4j777Z ~]# sudo systemctl start mysqld.service
[root@iZ2vc5lqzt23aweti4j777Z ~]# systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2023-12-19 16:25:42 CST; 4h 27min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 2810 (mysqld)
    Tasks: 28 (limit: 11861)
   Memory: 371.8M
   CGroup: /system.slice/mysqld.service
           └─2810 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Dec 19 16:25:35 iZ2vc5lqzt23aweti4j777Z systemd[1]: Starting MySQL Server...
Dec 19 16:25:42 iZ2vc5lqzt23aweti4j777Z systemd[1]: Started MySQL Server.
[root@iZ2vc5lqzt23aweti4j777Z ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.44 MySQL Community Server (GPL)

Copyright (c) 2000, 2023, 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> create database pbootcms
    -> ;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| pbootcms           |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> use pbootcms;
Database changed
mysql> create table subject(
    -> subjet_id int,
    -> subject_name varchar(20),
    -> subject_hours int
    -> )charset = utf8;
Query OK, 0 rows affected (0.01 sec)

mysql> insert into subject
    -> (subject_id, subject_name, subject_hours)
    -> values
    -> (001,"Communication skills", 100);
ERROR 1054 (42S22): Unknown column 'subject_id' in 'field list'
mysql> insert into subject (subjet_id, subject_name, subject_hours) values (001,"Communication skills", 100);
Query OK, 1 row affected (0.00 sec)

mysql> select * from subject;
+-----------+----------------------+---------------+
| subjet_id | subject_name         | subject_hours |
+-----------+----------------------+---------------+
|         1 | Communication skills |           100 |
+-----------+----------------------+---------------+
1 row in set (0.00 sec)

mysql> desc subject;
+---------------+-------------+------+-----+---------+-------+
| Field         | Type        | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| subjet_id     | int(11)     | YES  |     | NULL    |       |
| subject_name  | varchar(20) | YES  |     | NULL    |       |
| subject_hours | int(11)     | YES  |     | NULL    |       |
+---------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> show tables;
+--------------------+
| Tables_in_pbootcms |
+--------------------+
| subject            |
+--------------------+
1 row in set (0.00 sec)

mysql> 
文章来源:https://blog.csdn.net/DavidsonGong/article/details/135094649
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。