Skip to content

Blog

Basic MySQL Statements

This note collects common MySQL administration and SQL statements.

mysql -u root -p

On Linux, you may need to run it with sudo depending on the local installation and permissions.

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
-> ON DATABASE.*
-> TO 'user'@'localhost'
-> IDENTIFIED BY 'password';

The statement grants permissions on DATABASE to user with password password. MySQL statements end with ;.

mysql> use DATABASE;

After selecting a database, subsequent commands operate on that database by default.

SHOW DATABASES;

SHOW TABLES;

SHOW COLUMNS FROM table_name;

SHOW INDEX FROM table_name;

CREATE DATABASE database_name;
mysqladmin -u root -p create database_name
DROP DATABASE database_name;
mysqladmin -u root -p drop database_name
CREATE TABLE table_name(
-> id INT NOT NULL AUTO_INCREMENT,
-> title VARCHAR(100) NOT NULL,
-> author VARCHAR(40) NOT NULL,
-> date DATE,
-> PRIMARY KEY ( id )
-> )ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE table_name;

5. Insert, query, update, and delete records

Section titled “5. Insert, query, update, and delete records”
INSERT INTO table_name ( field1, field2,...fieldN )
VALUES
( value1, value2,...valueN );
SELECT column_name,column_name
FROM table_name
[WHERE Clause]
[LIMIT N][ OFFSET M]
UPDATE table_name SET field1=new-value1, field2=new-value2
[WHERE Clause]
DELETE FROM table_name [WHERE Clause]
  • WHERE: filter rows by conditions.
  • LIKE: match text patterns, usually with %.
  • UNION: merge result sets.
  • ORDER BY: sort query results.
  • GROUP BY: group rows for aggregate queries.
  • JOIN: combine rows from multiple tables.
  • IS NULL / IS NOT NULL: compare NULL values safely.

[1]. https://www.runoob.com/mysql/

PPPoE with Raspberry Pi

1. Install pppoe, pppoeconf, and pppstatus

Section titled “1. Install pppoe, pppoeconf, and pppstatus”

sudo apt-get install pppoe pppoeconf pppstatus

pppoeconf

Run the pppoeconf command and keep selecting “yes” through the prompts. During the process, you will be asked to enter your PPPoE account and password.

ifconfig

4. Share the ppp0 network through wlan0 as a hotspot

Section titled “4. Share the ppp0 network through wlan0 as a hotspot”

In Haoran.Qi/RaspberryPi, change eth0 to ppp0 on lines 71-74.

OSI Model

Open System Interconnection Reference Model (OSI) is a conceptual model proposed by the International Organization for Standardization (ISO). It is a standard framework that attempts to interconnect various computers worldwide.

According to recommendation X.200, OSI divides the computer network architecture into seven layers, labeled 1 to 7, with Layer 1 at the bottom.

The Application Layer provides interfaces for application software to establish communication with other applications. Examples include: HTTP, HTTPS, FTP, Telnet, SSH, SMTP, POP3, etc.

The Presentation Layer converts data into formats compatible with the recipient’s system, making it suitable for transmission (e.g., encoding, encryption, compression).

The Session Layer is responsible for establishing, managing, and terminating communication sessions between two computers on a network.

The Transport Layer adds a transport header (TH) to the data to form packets. It manages end-to-end transmission, error recovery, and flow control. Examples include: TCP and UDP.

The Network Layer handles routing and packet forwarding, adding network headers (NH) to data to form datagrams. Examples include: IP, ICMP, etc.

The Data Link Layer handles physical addressing, error detection, and synchronization. It packages packets into data frames. It is divided into two sub-layers: Logical Link Control (LLC) and Media Access Control (MAC). Examples include: Ethernet, Wi-Fi, GPRS, etc.

The Physical Layer transmits raw bit streams over physical media (voltage, pin specifications, cables, hubs, network adapters, etc.).

[1]. TCP-Over-DNS-Bypassing-Campus-Network-Charging

Gogs Configuration Overview

Gogs keeps default configuration in conf/app.ini. You normally do not edit that file directly, because the default configuration has been embedded into the binary since v0.6.0.

Create custom/conf/app.ini and override only the options you need.

Example repository root:

[repository]
ROOT = /home/jiahuachen/gogs-repositories

Example database password:

[database]
PASSWD = root

This approach protects custom configuration during binary replacement or source updates.

Development mode:

$ make
$ ./gogs web

Deployment mode:

  • Start normally with ./gogs web.
  • Use scripts from the scripts directory when running as a service.
  • Visit /install to complete first-run configuration.
  • server: protocol, domain, root URL, HTTP listen address, SSH options, static file path, and gzip.
  • repository: repository root, script type, forced private repositories, raw file rendering, and migration settings.
  • database: database type, host, name, user, password, and SQLite path.
  • security: install lock, secret key, login cookies, and reverse proxy authentication.
  • service: registration, captcha, mail notification, and cache avatar settings.
  • webhook: webhook type, queue length, delivery timeout, and TLS verification.
  • mailer: SMTP host, sender, username, password, and STARTTLS behavior.
  • log: log root path, output mode, level, and rotation settings.
  • git: diff display limits and Git operation timeouts.

[1]. https://www.cnblogs.com/sanduzxcvbnm/p/11351991.html

[2]. Build-Git-Server-Using-Gogs-with-Docker-and-Employ-Frp-with-Caddy-Reverse-Proxy

Solution to MATLAB Chinese garbled characters in English operating systemChinese characters in the MATLAB editor under English operating environment will be displayed as garbled characters.

ReasonFollow the online tutorials to change the system environment configuration```

Section titled “ReasonFollow the online tutorials to change the system environment configuration```”

Control Panel,Region,Administrative,Language for non-Unicode Option Set as Chinese(Simplified,China)

Control Panel,Region,Formats,Format Option Set as Chinese(Simplified,China).

After this setting, the system format changes to Chinese, and the matlab display language also changes to Chinese. However, when plotting, garbled characters will still be displayed.
The main reason is character set mismatch.
## MethodFind the lcdata.xml file in the MATLAB directory. When the file is empty, MATLAB automatically calls the system default character set. Therefore, copy lcdata_utf8.xml in the MATLAB directory and rename it to lcdata.xml. Replace the content with the following```
<?xml version="1.0" encoding="UTF-8" ?>
<!-- MathWorks Locale Database -->
<!-- File Name: lcdata_utf8.xml -->
<!-- Copyright 2007-2016 The MathWorks, Inc. -->
<lcdata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="lcdata.xsd">
<!-- Codeset entry -->
<codeset>
<encoding name="UTF-8">
<encoding_alias name="utf8"/>
<encoding_alias name="EUC-CN"/>
<encoding_alias name="euccn"/>
<encoding_alias name="1252"/>
<encoding_alias name="ISO8859-15"/>
<encoding_alias name="ISO885915"/>
<encoding_alias name="ISO8859-14"/>
<encoding_alias name="ISO885914"/>
<encoding_alias name="ISO8859-1"/>
<encoding_alias name="ISO88591"/>
<encoding_alias name="936"/>
</encoding>
</codeset>
<!-- Locale entries -->
<locale name="en_US" encoding="UTF-8" xpg_name="en_US.UTF-8">
<alias name="en"/>
</locale>
<locale name="zh_CN" encoding="UTF-8" xpg_name="zh_CN.UTF-8">
<alias name="zh-Hans"/>
<alias name="zh-Hans-CN"/>
</locale>
</lcdata>