Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I dont know whether to post this in the programming section or just here at the server section.
I have got a mysql db running on my pentium3. Port 80, 20, 21, 3306 and 3307 are forwarded to that computer. And the domain of my pentium3 is http://backwardsdown.no-ip.org.
Now I want to connect to my db with C++ from my pentium4. I have downloaded and installed mysql++. The tutorial starts with a example named "resetdb". It compiles fine.
Code:
/***********************************************************************
resetdb.cpp - (Re)initializes the example database, mysql_cpp_data.
You must run this at least once before running most of the other
examples, and it is helpful sometimes to run it again, as some of
the examples modify the table in this database.
Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
Others may also hold copyrights on code in this file. See the CREDITS
file in the top directory of the distribution for details.
This file is part of MySQL++.
MySQL++ is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
MySQL++ is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with MySQL++; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
***********************************************************************/
#include "util.h"
#include <mysql++.h>
#include <iostream>
using namespace std;
int
main(int argc, char *argv[])
{
// Connect to database server
mysqlpp::Connection con;
try {
cout << "Connecting to database server..." << endl;
connect_to_db(argc, argv, con, "");
}
catch (exception& er) {
cerr << "Connection failed: " << er.what() << endl;
return 1;
}
// Create new sample database, or re-create it. We suppress
// exceptions, because it's not an error if DB doesn't yet exist.
bool new_db = false;
{
mysqlpp::NoExceptions ne(con);
mysqlpp::Query query = con.query();
if (con.select_db(kpcSampleDatabase)) {
// Toss old table, if it exists. If it doesn't, we don't
// really care, as it'll get created next.
cout << "Dropping existing stock table..." << endl;
query.execute("drop table stock");
}
else {
// Database doesn't exist yet, so create and select it.
if (con.create_db(kpcSampleDatabase) &&
con.select_db(kpcSampleDatabase)) {
new_db = true;
}
else {
cerr << "Error creating DB: " << con.error() << endl;
return 1;
}
}
}
// Create sample data table within sample database.
cout << "Creating new stock table..." << endl;
try {
// Send the query to create the table and execute it.
mysqlpp::Query query = con.query();
query <<
"CREATE TABLE stock " <<
"(item CHAR(20) NOT NULL, " <<
" num BIGINT, " <<
" weight DOUBLE, " <<
" price DOUBLE, " <<
" sdate DATE) " <<
"ENGINE = InnoDB " <<
"CHARACTER SET utf8 COLLATE utf8_general_ci";
query.execute();
// Set up the template query to insert the data. The parse()
// call tells the query object that this is a template and
// not a literal query string.
query << "insert into %5:table values (%0q, %1q, %2, %3, %4q)";
query.parse();
// Set the template query parameter "table" to "stock".
query.def["table"] = "stock";
// Notice that we don't give a sixth parameter in these calls,
// so the default value of "stock" is used. Also notice that
// the first row is a UTF-8 encoded Unicode string! All you
// have to do to store Unicode data in recent versions of MySQL
// is use UTF-8 encoding.
cout << "Populating stock table..." << endl;
query.execute("Nürnberger Brats", 92, 1.5, 8.79, "2005-03-10");
query.execute("Pickle Relish", 87, 1.5, 1.75, "1998-09-04");
query.execute("Hot Mustard", 75, .95, .97, "1998-05-25");
query.execute("Hotdog Buns", 65, 1.1, 1.1, "1998-04-23");
cout << (new_db ? "Created" : "Reinitialized") <<
" sample database successfully." << endl;
}
catch (const mysqlpp::BadQuery& er) {
// Handle any query errors
cerr << "Query error: " << er.what() << endl;
return 1;
}
catch (const mysqlpp::BadConversion& er) {
// Handle bad conversions
cerr << "Conversion error: " << er.what() << endl <<
"\tretrieved data size: " << er.retrieved <<
", actual size: " << er.actual_size << endl;
return 1;
}
catch (const mysqlpp::Exception& er) {
// Catch-all for any other MySQL++ exceptions
cerr << "Error: " << er.what() << endl;
return 1;
}
return 0;
}
[/quote]Once you have the examples building, you need to initialize the sample database by running the resetdb example. The usage of resetdb is as follows:
resetdb [host [user [password [port]]]]
If you leave off host, localhost is assumed. If you leave off user, your current username is assumed. If you leave of the password, it is assumed that you don't need one. And if you leave off the port, it will use the standard MySQL port number.
The user you give resetdb needs to be an account with permission to create databases. Once the database is created you can use any account that has full permission to the sample database mysql_cpp_data.[/quote]
niels@niels-desktop:~/Downloads/mysql++-2.1.1/mysql++-2.1.1/examples$ resetdb backwardsdown.no-ip.org username password 3306
Connecting to database server...
Connection failed: Lost connection to MySQL server during query
But I dont know where the problem lies. Can someone help me?
Php pages like phpmyadmin are working fine.
Last edited by BackwardsDown; 12-10-2006 at 05:40 AM.
As far as I know, there is an option to skip networking that will disable this. Read the manual and check that the server is not started with that option.
Second the user that you use needs to be in the user table with the given address or hostname. Wildcards are allowed.
On my pentium3 the script works when I type "localhost" but not when I type "backwardsdown.no-ip.org", so it blocks remote connections.
Quote:
mysql> GRANT ALL PRIVILEGES ON mysql_cpp_data.* TO `backwardsdown`@`%` IDENTIFIED BY '***************';
Query OK, 0 rows affected (0.38 sec)
So that seems allright.
I have commented "bind-address" and "skip-external-lockint" out.
But it still blocks remote connections. (I dont run a firewall)
My my.cnf:
Quote:
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "/var/lib/mysql/my.cnf" to set server-specific options or
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/se...variables.html
# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/english
#bind-address = x.x.x.x
#skip-external-locking
#
# For compatibility to other Debian packages that still use
# libmysqlclient10 and libmysqlclient12.
old_passwords = 1
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1
#
# * Fine Tuning
#
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 128K
thread_cache_size = 8
#
# * Query Cache Configuration
#
query_cache_limit = 1048576
query_cache_size = 16777216
query_cache_type = 1
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
#log = /var/log/mysql/mysql.log
#
# Error logging goes to syslog. This is a Debian improvement
#
# Here you can see queries with especially long duration
#log_slow_queries = /var/log/mysql/mysql-slow.log
#
# The following can be used as easy to replay backup logs or for replication.
#server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
# WARNING: Using expire_logs_days without bin_log crashes the server! See README.Debian!
expire_logs_days = 10
max_binlog_size = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
#
# * BerkeleyDB
#
# According to an MySQL employee the use of BerkeleyDB is now discouraged
# and support for it will probably cease in the next versions.
skip-bdb
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
# You might want to disable InnoDB to shrink the mysqld process by circa 100MB.
#skip-innodb
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem
[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
[isamchk]
key_buffer = 16M
#
# * NDB Cluster
#
# See /usr/share/doc/mysql-server-*/README.Debian for more information.
#
# The following configuration is read by the ndbd storage daemons,
# not from the ndb_mgmd management daemon.
#
# [MYSQL_CLUSTER]
# ndb-connectstring=127.0.0.1
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.