c++之web框架cppcms安装配置和c++之CppDB安装配置

一、CppCMS
去cppcms的官网(https://sourceforge.net/projects/cppcms/files/cppcms/)下载适合自己的版本;

$ wget https://jaist.dl.sourceforge.net/project/cppcms/cppcms/1.2.1/cppcms-1.2.1.tar.bz2
$ tar xf cppcms-1.2.1.tar.bz2 
$ sudo mv cppcms-1.2.1 /usr/local/
$ cd /usr/local/cppcms-1.2.1/

在切换目录下面添加build文件夹:

$ sudo mkdir build
$ cd build
$ sudo cmake -DCMAKE_INSTALL_PREFIX=/usr/local ..
$ sudo make -j4
$ sudo make install

注意,在cppcms-1.2.1目录下有个examples文件,里面是cppcms的demo,可以直接参考学习。

问题1:运行时,出现”error while loading shared libraries: libcppcms.so.1:“
解决办法:参考https://blog.csdn.net/hankerbit/article/details/83834349

我在运行hello world时:./hello -c config.js,发现外网无法访问,加了一个"ip"字段,解决!

{
        "service" : {
                "api" : "http",
                "port" : 9090,
                "ip":"172.16.126.136"
        },
        "http" : {
                "script" : "/hello"
        }
}

二、CppDB
去cppcms的官网(https://sourceforge.net/projects/cppcms/files/cppdb/)下载适合自己的版本;

$ wget https://jaist.dl.sourceforge.net/project/cppcms/cppdb/0.3.1/cppdb-0.3.1.tar.bz2
$ tar xf cppdb-0.3.1.tar.bz2 
$ cd cppdb-0.3.1

在切换目录下面添加build文件夹:

$ sudo mkdir build
$ cd build
$ sudo cmake -DCMAKE_INSTALL_PREFIX=/usr/local ..
$ sudo make -j4
$ sudo make install

安装好CppDB后,还需要安装mysql:
去https://dev.mysql.com/downloads/mysql/下载dmg文件

安装后直接在命令行输入mysql会提示mysql: command not found,需要先将其添加到环境变量:

vim ~/.bash_profile
添加以下指令:

export PATH=${PATH}:/usr/local/mysql/bin
保存后立即使其生效:

source ~/.bash_profile


使用安装过程中设置的,root用户的登录密码,用它登录 MySQl:
xxx@madeMacBook-Pro bin % mysql -u root -p         
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 96
Server version: 8.0.19 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


mysql> select Host, user from mysql.user;
+-----------+------------------+
| Host      | user             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
4 rows in set (0.00 sec)

mysql> create user maqianli identified by 'maqianli';
Query OK, 0 rows affected (0.03 sec)

mysql> select Host, User from mysql.user;
+-----------+------------------+
| Host      | User             |
+-----------+------------------+
| %         | maqianli         |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+

远程账号创建完成了,在程序里面连接发现还是没有权限,刚才我们只是创建了用户,还没有对这个用户分配权限;

mysql> GRANT ALL PRIVILEGES ON *.* TO 'maqianli'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.01 sec)

all代表接受所有操作,比如 select,insert,delete….; . 代表所有库下面的所有表;% 代表这个用户允许从任何地方登录;为了安全期间,这个%可以替换为你允许的ip地址;

然后刷新mysql用户权限相关表
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

maqianli@madeMacBook-Pro ~ % mysql -h 192.168.1.104 -u maqianli -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2727
Server version: 8.0.19 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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> \q
Bye

maqianli@madeMacBook-Pro ~ % mysql -h localhost -u maqianli -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2736
Server version: 8.0.19 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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> \q
Bye
maqianli@madeMacBook-Pro ~ % mysql -h localhost -P 3307 -u maqianli -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2738
Server version: 8.0.19 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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服务的启动、重启、停止
# 启动
sudo /usr/local/mysql/support-files/mysql.server start
# 重启
sudo /usr/local/mysql/support-files/mysql.server restart
# 停止
sudo /usr/local/mysql/support-files/mysql.server stop


登录进入mysql
查看当前的数据库
show databases;
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

显示某某数据库的表单
mysql> show tables in mysql;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| component                 |
| db                        |
| default_roles             |
| engine_cost               |
| func                      |
| general_log               |
| global_grants             |
| gtid_executed             |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| password_history          |
| plugin                    |
| procs_priv                |
| proxies_priv              |
| role_edges                |
| server_cost               |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
33 rows in set (0.01 sec)

剩下的就是建库、建表、表的增删改查sql语句了。

mysql> create database student character set utf8mb4;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE TABLE info(
    -> id INT PRIMARY KEY auto_increment, 
    -> name VARCHAR(255) NOT NULL, 
    -> age INTEGER NOT NULL
    -> );
Query OK, 0 rows affected (0.02 sec)

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

mysql> insert into info (name, age) values('name0', 0);
Query OK, 1 row affected (0.00 sec)



 

你可能感兴趣的:(Server端)