歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

CentOS mysql 配置

1.安裝mysql
#yum install mysql-server mysql-devel mysql
2.查看mysql版本
# mysql --version
mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1
3.配置mysql
# vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0


[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
default-character-set = utf8 --添加
[mysql] --添加
default-character-set = utf8 --添加
4.啟動mysql
# chkconfig mysqld on
-----設置mysql服務隨系統啟動
# chkconfig --list mysqld
mysqld 0:關閉 1:關閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關閉
----確認mysql自啟動,如果2--5為啟用則ok
# /etc/rc.d/init.d/mysqld start
正在啟動 mysqld: 【確定】
5.查詢是否已經啟動
# ps -ef |grep mysql
root 1643 1 0 01:03 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql 1751 1643 0 01:03 pts/0 00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root 2065 16869 0 01:04 pts/0 00:00:00 grep mysql
6.登陸 設置密碼
# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
---默認無密碼登陸
mysql> select user,host,password from mysql.user;
查看用戶信息,初始用戶信息如下


+------+--------------------------------+-------------------+
| user | host | password |
+------+--------------------------------+-------------------+
| root | localhost | |
| root | localhost.localdomain | |
| root | 127.0.0.1 | |
| | localhost | |
| | localhost.localdomain | |
+------+--------------------------------+----------+
5 rows in set (0.00 sec)
----可見初始密碼均為空
mysql> set password for root@localhost=password('設置的密碼');
mysql> set password for root@'localhost.localdomain'=password('設置的密碼*');
查看設置結果


mysql> select user,host,password from mysql.user;
+------+-----------------------+-------------------------------------------+
| user | host | password |
+------+-----------------------+-------------------------------------------+
| root | localhost | *400E14D31C7C82FFE6AB2FD220973E029CE00963 |
| root | localhost.localdomain | *400E14D31C7C82FFE6AB2FD220973E029CE00963 |
| root | 127.0.0.1 | |
| | localhost | |
| | localhost.localdomain | |
+------+-----------------------+-------------------------------------------+
5 rows in set (0.00 sec)
7. 刪除匿名的用戶,以防止非法登陸。
mysql> delete from mysql.user where user='';
8. 接下來就可以正常使用mysql 了。

Copyright © Linux教程網 All Rights Reserved