日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql安装后配置

發布時間:2024/9/30 数据库 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql安装后配置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1:配置my.cnf

原來的配置

[root@feng02 ~]# cat /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

修改后

[root@feng02 ~]# cat /etc/my.cnf [client] password = 123456 port = 3306 default-character-set=utf8 [mysql] default-character-set = utf8 [mysqld] port = 3306 character_set_server=utf8 character_set_client=utf8 collation-server=utf8_general_ci lower_case_table_names=1 max_connections=1000 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
2:初始化MySQL

輸入:/usr/bin/mysql_install_db

[root@feng02 ~]# /usr/bin/mysql_install_db Installing MySQL system tables... 150905 13:51:04 [Warning] /usr/libexec/mysqld: ignoring option '--character-set-client-handshake' due to invalid value 'utf8' OK Filling help tables... 150905 13:51:04 [Warning] /usr/libexec/mysqld: ignoring option '--character-set-client-handshake' due to invalid value 'utf8' OKTo start mysqld at boot time you have to copy support-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands:/usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h feng02 password 'new-password'Alternatively you can run: /usr/bin/mysql_secure_installationwhich will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with: cd /usr ; /usr/bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.pl cd /usr/mysql-test ; perl mysql-test-run.plPlease report any problems with the /usr/bin/mysqlbug script!
3:啟動Mysql

[root@feng02 ~]# service mysqld start Starting mysqld: [ OK ]
4:連接Mysql

輸入:mysql -uroot -p

直接回車,不用輸入密碼

[root@feng02 ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.73 Source distributionCopyright (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> update user set password=password('123456') where user='root'; ERROR 1046 (3D000): No database selected mysql> show database; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.00 sec)
設置root的密碼:

輸入:use mysql;

輸入:update user set password=password('123456') where user='root';

mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed mysql> update user set password=password('123456') where user='root'; Query OK, 3 rows affected (0.01 sec) Rows matched: 3 Changed: 3 Warnings: 0mysql> exit Bye
5:重啟mysql

輸入:service mysqld restart

[root@feng02 ~]# service mysqld restart

Stopping mysqld: [ OK ] Starting mysqld: [ OK ]
6:使用密碼登陸:

[root@feng02 ~]# mysql -uroot -p123456 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.1.73 Source distributionCopyright (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>
7:設置允許遠程登錄

輸入:use mysql;
輸入:select host,user,password from user;
輸入:update user set host='%' where user='root' and host='localhost';
輸入:flush privileges;
輸入: exit;

mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed mysql> select host,user,password from user; +-----------+------+-------------------------------------------+ | host | user | password | +-----------+------+-------------------------------------------+ | localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | feng02 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | 127.0.0.1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | localhost | | | | feng02 | | | +-----------+------+-------------------------------------------+ 5 rows in set (0.00 sec)mysql> update user set host='%' where user='root' and host='localhost'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0mysql> flush privileges; Query OK, 0 rows affected (0.02 sec)mysql> exit; Bye


8:連接需要輸入IP或主機名了
[root@feng02 ~]# mysql -uroot -p123456 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) [root@feng02 ~]# mysql -hfeng02 -uroot -p123456 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 5.1.73 Source distribution


總結

以上是生活随笔為你收集整理的mysql安装后配置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。