In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to change the database name of linux MySQL". In the daily operation, I believe many people have doubts about how to change the database name of linux MySQL. The editor consulted all kinds of information and sorted out a simple and easy-to-use operation method. I hope it will be helpful to answer the doubt of "how to change the database name of linux MySQL". Next, please follow the editor to study!
In Linux environment: the default data file storage directory for MySQL is / var/lib/mysql. I want to do two things today, rename the library (tested three methods), and change the location of the MySQL database directory. Rename the library: 1. RENAME DATABASE zhoz_db to zhoz_db_bak
Mysql > RENAME DATABASE zhoz_db to zhoz_db_bak; 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 test to test_bak' at line 1 reported an error. I looked it up online as if it could be done in mysql6 environment. The test environment is mysql5.
2. Mv / var/lib/mysql/zhoz_db / var/lib/mysql/zhoz_db_bak was successfully implemented and its name was changed. But enter the MyAdmin to find this library, but can not display the table. In fact, it is not possible to change the name alone. The corresponding table also needs to be changed. Of course, if it is only used as a backup, it is OK.
3. The best of both worlds: operate under phpMyAdmin: select the library to be renamed the [Operation] in the upper right corner of the → point. Rename → to "zhoz_db_bak" → to change the location of the MySQL database directory: the default data file storage directory of MySQL is / var/lib/, target moved to / home/zhozcom_data:
1. Create a data directory under the home directory: cd / home mkdir zhozcom_data
2. Stop the MySQL service process: mysql-u root-p shutdown
3. Move the entire directory / var/lib/mysql to / home/zhozcom_data mv / var/lib/mysql / home/zhozcom_data/
This moves the data file of MySQL to / home/zhozcom_data/mysql
4. Find the my.cnf configuration file if there is no my.cnf configuration file in the / etc/ directory, please find the * .cnf file under / usr/share/mysql/, copy one of them to / etc/ and rename it to my.cnf. The command is as follows: [root@test1 mysql] # cp / usr/share/mysql/my.cnf / etc/my.cnf
5. Edit the configuration file / etc/my.cnf of MySQL to ensure that MySQL can work properly, you need to specify the location where the mysql.sock file is generated. Modify the value of socket=/var/lib/mysql/mysql.sock as follows: the socket=/home/zhozcom_data/mysql.sock operation is as follows: [root@zhoz etc] # vi my.cnf # The MySQL server [mysqld] port = 3306#socket = / var/lib/mysql/mysql.sock (original content, usually comment this line with # for security) socket=/home/zhozcom_data/mysql / mysql.sock (plus this line)
6. Modify MySQL startup script / etc/init.d/mysql modify MySQL startup script / etc/init.d/mysql: modify datadir=/var/lib/mysql to the current path: datadir=/home/zhozcom_data/mysql. Method: [root@zhoz etc] # vi / etc/init.d/mysql # datadir=/var/lib/mysql (comment this line) datadir=/home/data/mysql (plus this line)
7. Restart the MySQL service / etc/init.d/mysql start
Everything OK, if not, then check the permissions: drwxr-xr-x directory. It is also necessary to restart the library.
At this point, the study on "how to change the database name of linux MySQL" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.