Это старая версия документа!


MySQL - первый запуск

Будем считать, что сам пакет MySQL у Вас установлен(если «нет», просто установите его). Поэтому переходим сразу к делу….

Создаем каталог БД, устанавливаем базы по умолчанию, и даем права:

 # mkdir /var/lib/mysql/mysql
 # mysql_install_db 
 # chown -R mysql.mysql /var/lib/mysql

Запускаем MySQL и пытаемся в него зайти:

 # /usr/bin/mysqld_safe &
 # mysql -u root
  Welcome to the MySQL monitor. Commands end with ; or \g. 
  Your MySQL connection id is 10 to server version:5.0.51-log Source distribution
  
 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. 
 mysql>

Приглашение на выполнение запросов и команд MySQL мы получили, дальше даём пользователю root пароль. Перед этим можно посмотреть базы:

 mysql> show databases;
 +--------------------+
 | Database           |
 +--------------------+
 | information_schema |
 | test               |
 +--------------------+
 2 rows in set (0.00 sec)
 mysql> set password for 'root'@'localhost' = password('mypassword'); 
 mysql> FLUSH PRIVILEGES;
 mysql>\q

Всё, должен запустится и работать после перезагрузки то же (не забыть дать права на запуск rc.mysqld).<br /> Можно проверить:

 # mysqladmin -u root -p status
 Enter password:
 
Uptime: 136  Threads: 1  Questions: 2  Slow queries: 0  Opens: 12  Flush tables: 1 Open tables: 6  Queries per second avg: 0.015

Или можно использовать такой вариант настройки MySQL, ответив на вопросы mysql_secure_installation:

 # mysql_install_db --user=mysql
 # chmod 755 /etc/rc.d/rc.mysqld
 # /etc/rc.d/rc.mysqld start
 # mysql_secure_installation

После, нужно зайти как root для работы с MySQL:

 # mysql -u root -p
 Enter password:
 Welcome to the MySQL monitor.  Commands end with ; or \g.
 Your MySQL connection id is 77
 Server version: 5.0.51-log Source distribution
 Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
 mysql>

Если надо управлять базами удалённо, то необходимо добавить опцию -h

 # mysql  -h192.168.10.195 -uroot -p
 Enter password:
 Welcome to the MySQL monitor.  Commands end with ; or \g.
 Your MySQL connection id is 77
 Server version: 5.0.51-log Source distribution
 
 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. 
 
 mysql>

Если при подключении выдаёт ошибку:

 # mysql  -h192.168.10.195 -uroot –p
 ERROR 2003: (HY000):Cannot connect to MySQL server on ‘192.168.10.195’ (111)

То необходимо закаментарить –skip-networking в стартовом скрипте и my.cnf. SKIP=«–skip-networking»

- Обсуждаем на форуме -

Навигация
Печать/экспорт
QR Code
QR Code wiki:articles:mysql_first (generated for current page)