Ubuntu Linux Start / Restart / Stop Apache Web Server & MySQL Server


How do I start, restart or stop Apache 2 web server & MySQL server under Ubuntu Linux operating systems?

/etc/init.d/apache2 is service script used to start / stop / restart the Apache2 service under Debian or Ubuntu Linux. You need to login as root or use sudo command restart Apache.
sudo -i
Enter your root password
Task: Start Apache 2 Server
# /etc/init.d/apache2 start
or
$ sudo /etc/init.d/apache2 start

Task: Restart Apache 2 Server
# /etc/init.d/apache2 restart
or
$ sudo /etc/init.d/apache2 restart

Task: Stop Apache 2 Server
# /etc/init.d/apache2 stop
or
$ sudo /etc/init.d/apache2 stop

Task: Start MySQL Server
# /etc/init.d/mysql start
or
$ sudo /etc/init.d/mysql start

Task: Restart MySQL Server
# /etc/init.d/mysql restart
or
$ sudo /etc/init.d/mysql restart

Task: Stop MySQL Server
# /etc/init.d/mysql stop
or
$ sudo /etc/init.d/mysql stop

Breaking referential integrity in MySql


Integrity constraint violation: 1452 Cannot add or update a child row: a foreign
key constraint fails (`sumaria_magento/mg_catalog_category_product_index`,
CONSTRAINT `FK_CATALOG_CATEGORY_PRODUCT_INDEX_PRODUCT_ENTITY` FOREIGN KEY
(`product_id`) REFERENCES `mg_catalog_product_entity` (`entity_id)

Reason..
The Constraint dont find any Parent keys in parent table. But children for these Product ids are present. That means… database have Children entries without Parent …

Is it possible to break the referential integrity when a foreign key constraint is set on an InnoDB table? The answer is an (unfortunate?) yes. It’s not a bad feature that it’s possible to temporarily turn @@foreign_key_checks off, because sometimes it’s necessary to change data in a way that referential integrity needs to be broken during the modification process. But most of the time, the data should be valid, when modification is finished. So what can be done?

A little example demonstrates this:

mysql> CREATE TABLE table_one (
->   id INT NOT NULL AUTO_INCREMENT PRIMARY KEY
->   ) ENGINE = InnoDB;
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO table_one (id) VALUES
->   (1), (2), (3);
Query OK, 3 rows affected (0.02 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> CREATE TABLE table_two (
->   id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
->   id_table_one INT NOT NULL,
->   FOREIGN KEY (id_table_one) REFERENCES table_one(id))
->   ENGINE = InnoDB;
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO table_two (id_table_one) VALUES
->   (3), (2), (2), (3), (1);
Query OK, 5 rows affected (0.00 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> SELECT * FROM table_one; SELECT * FROM table_two;
+—-+
| id |
+—-+
|  1 |
|  2 |
|  3 |
+—-+
3 rows in set (0.00 sec)

+—-+——-+
| id | id_table_one |
+—-+——-+
|  5 |     1 |
|  2 |     2 |
|  3 |     2 |
|  1 |     3 |
|  4 |     3 |
+—-+——-+
5 rows in set (0.00 sec)

mysql> INSERT INTO table_two (id_table_one) VALUES (4);
ERROR 1452 (23000): Cannot add or update a
child row: a foreign key constraint fails
(`test/table_two`, CONSTRAINT `table_two_ibfk_1` FOREIGN KEY
(`id_table_one`) REFERENCES `table_one` (`id`))

mysql> SET @@foreign_key_checks = 0;
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO table_two (id_table_one) VALUES
->   (2), (1), (4), (2);
Query OK, 4 rows affected (0.00 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> SET @@foreign_key_checks = 1;
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT * FROM table_one; SELECT * FROM table_two;
+—-+
| id |
+—-+
|  1 |
|  2 |
|  3 |
+—-+
3 rows in set (0.00 sec)

+—-+——-+
| id | id_table_one |
+—-+——-+
|  5 |     1 |
|  7 |     1 |
|  2 |     2 |
|  3 |     2 |
|  6 |     2 |
|  9 |     2 |
|  1 |     3 |
|  4 |     3 |
|  8 |     4 |
+—-+——-+
9 rows in set (0.00 sec)

The record no 8 in table table_two has now an invalid value, due to the fact that we have set the foreign key verification temporarily to off (0).