linux下mysql的簡單配置

一、設置字符編碼 輸入命令: [root@localhost ~]# vi /etc/my.cnf 最後一行加入:default-character-set=utf8,保存! 二、啓動mysql服務: 輸入命令: [root@localhost ~]# service mysqld start 返回一下信息則表示已經啓動成功 Initializing MySQL database: Installing MySQL system tables... OK Filling help tables... OKmysql

To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your systemlinux

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands:sql

/usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'數據庫

Alternatively you can run: /usr/bin/mysql_secure_installationdom

which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers.tcp

See the manual for more instructions.編碼

You can start the MySQL daemon with: cd /usr ; /usr/bin/mysqld_safe &rest

You can test the MySQL daemon with mysql-test-run.pl cd /usr/mysql-test ; perl mysql-test-run.plcode

Please report any problems with the /usr/bin/mysqlbug script!server

[  OK  ]

Starting mysqld: [ OK ]

三、設置開機啓動: 輸入命令: [root@localhost ~]# chkconfig --add mysqld [root@localhost ~]# chkconfig mysqld on

四、查看開機啓動設置是否成功 輸入命令: [root@localhost ~]# chkconfig --list | grep mysql* mysqld 返回一下信息則表示已經設置成功 grep: mysqld: No such file or directory [root@localhost ~]# chkconfig --list | grep mysql* mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

五、建立root管理員: 輸入命令:(設置用戶名爲root,密碼爲123456) [root@localhost ~]# mysqladmin -u root password 123456

六、登陸數據庫: 輸入命令: [root@localhost ~]# mysql -u root -p Enter password: 返回一下信息則表示登錄成功 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

七、若是是你的mysql數據庫是虛擬機linux端安裝的,可能會遇到遠程訪問不了的問題,解決方案以下: (1)修改防火牆,開啓3306端口。 輸入命令: [root@localhost ~]# vi /etc/sysconfig/iptables 添加一行: -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT (2)重啓服務 輸入命令: [root@localhost ~]# service iptables restart 返回信息: iptables: Flushing firewall rules: [ OK ] iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Unloading modules: [ OK ] iptables: Applying firewall rules: [ OK ] (3)受權用戶從遠程登陸 具體步驟:登錄到mysql 首先 use mysql; mysql> update user set host='%' where user = 'root'; 返回信息: ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' 而後查看了下數據庫的host信息以下: mysql> select host from user where user = 'root'; +-----------------------+ | host | +-----------------------+ | % | | 127.0.0.1 | | localhost.localdomain | +-----------------------+ 3 rows in set (0.00 sec) host已經有了%這個值,因此直接運行命令: mysql>flush privileges;

恭喜你,到此爲止,你再遠程登錄就能夠登錄成功了。

相關文章
相關標籤/搜索