MySQL duomenų bazės sukūrimas
MySQL duomenų bazei sukurti patogu naudoti phpMyAdmin įrankį, bet galima naudoti ir kitą.
Norint pasileisti phpMyAdmin įrankį naršyklėje įveskite adresą http://localhost/phpmyadmin. Nepamirškite prieš tai XAMPP Control panelėje paleisti Apache ir MySQL modulius.
Norint sukurti naują duomenų bazę pasirinkite nuorodą
![New DB](../img/it/new_db.jpg)
Sukūrus naują duomenų bazę jūsų iš karto paprašys sukurti pirmą lentelę - įveskite lentelės pavadinimą (pvz., books), stulpelių skaičių ir spauskite mygtuką![New table](../img/it/new_table.jpg)
Toliau reikia užpildyti lentelę su laukų pavadinimais, jų tipais ir kitais nustatymais, tada spausti apačioje esantį mygtuką![New table fields](../img/it/new_table_fields.jpg)
Arba tiesiog atsidarykite SQL skiltį:
![SQL window](../img/it/sql.jpg)
Įveskite SQL kodą ir spauskite mygtuką
Norint pasileisti phpMyAdmin įrankį naršyklėje įveskite adresą http://localhost/phpmyadmin. Nepamirškite prieš tai XAMPP Control panelėje paleisti Apache ir MySQL modulius.
Norint sukurti naują duomenų bazę pasirinkite nuorodą
New
, įveskite duomenų bazės pavadinimą (pvz., library), nurodykite koduotės palyginimą (angl. collation) utf8mb4_unicode_ci
ir spauskite mygtuką Create
:![New DB](../img/it/new_db.jpg)
Sukūrus naują duomenų bazę jūsų iš karto paprašys sukurti pirmą lentelę - įveskite lentelės pavadinimą (pvz., books), stulpelių skaičių ir spauskite mygtuką
Go
:
![New table](../img/it/new_table.jpg)
Toliau reikia užpildyti lentelę su laukų pavadinimais, jų tipais ir kitais nustatymais, tada spausti apačioje esantį mygtuką
Save
:
![New table fields](../img/it/new_table_fields.jpg)
Arba tiesiog atsidarykite SQL skiltį:
![SQL window](../img/it/sql.jpg)
Įveskite SQL kodą ir spauskite mygtuką
Go
:
--
-- Table structure for table `authors`
--
CREATE TABLE `authors` (
`id` bigint(20) UNSIGNED NOT NULL,
`first_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`middle_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`last_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`gender` tinyint(1) UNSIGNED NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
--
-- Table structure for table `books`
--
CREATE TABLE `books` (
`id` bigint(20) UNSIGNED NOT NULL,
`title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`description` text COLLATE utf8mb4_unicode_ci NOT NULL,
`isbn` varchar(13) COLLATE utf8mb4_unicode_ci NOT NULL,
`year` year(4) NOT NULL,
`pages` mediumint(9) NOT NULL,
`price` decimal(8,2) NOT NULL,
`publisher_id` bigint(20) UNSIGNED NOT NULL,
`genre_id` bigint(20) UNSIGNED NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
--
-- Table structure for table `books_authors`
--
CREATE TABLE `books_authors` (
`id` bigint(20) UNSIGNED NOT NULL,
`book_id` bigint(20) UNSIGNED NOT NULL,
`author_id` bigint(20) UNSIGNED NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
--
-- Table structure for table `genres`
--
CREATE TABLE `genres` (
`id` bigint(20) UNSIGNED NOT NULL,
`title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
--
-- Table structure for table `orders`
--
CREATE TABLE `orders` (
`id` bigint(20) UNSIGNED NOT NULL,
`book_id` bigint(20) UNSIGNED NOT NULL,
`user_id` bigint(20) UNSIGNED NOT NULL,
`taken` timestamp NULL DEFAULT NULL,
`returned` timestamp NULL DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
--
-- Table structure for table `publishers`
--
CREATE TABLE `publishers` (
`id` bigint(20) UNSIGNED NOT NULL,
`title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`website` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `authors`
--
ALTER TABLE `authors`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `books`
--
ALTER TABLE `books`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `books_authors`
--
ALTER TABLE `books_authors`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `genres`
--
ALTER TABLE `genres`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `orders`
--
ALTER TABLE `orders`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `publishers`
--
ALTER TABLE `publishers`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `authors`
--
ALTER TABLE `authors`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `books`
--
ALTER TABLE `books`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `books_authors`
--
ALTER TABLE `books_authors`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `genres`
--
ALTER TABLE `genres`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `orders`
--
ALTER TABLE `orders`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `publishers`
--
ALTER TABLE `publishers`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
COMMIT;