linux下安装mysql(实践版)_MySQL
【环境及文件版本】
red hat linux v6.2
mysql linux 版 x86-x64 v5.6
【准备需要的文件】
首先去官网下载mysql的linux版本,可以针对安装的操作系统选择合适的版本。
然后将文件解压到一个目录,例如 /usr/local/中,并重命名为mysql。确保最终所有的文件在/usr/local/mysql/这个目录中,使用命令行时,也需要定位到此目录,后续的操作都是在这个目录中完成的。
【初始化数据库文件】
然后拷贝support-files/my-default.cnf 到 当前目录,并命名为my.cnf,并修改其中内容如下:
[mysqld]
skip-name-resolve #跳过表扫描,可以加快mysql的执行树的
lower_case_table_names=1 #表名全部使用小写
datadir=/usr/local/mysql/data/ #设定数据文件存放位置
socket=/usr/local/mysql/mysql.sock
user=mysql
character-set-server=utf8 #设定server的字符集,防止中文乱码
# Disabling symbolic-links isrecommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/usr/local/mysql/log/mysqld.log #注意,这里要手动创建一下log目录
pid-file=/usr/local/mysql/mysqld.pid
然后执行数据库初始化脚本文件:
./scripts/mysql_install_db --defaults-file=my.cnf #后面的参数表示使用上一步定义的my.cnf来初始化数据库。
等待若干秒后,可以查看 data 目录查增加了 mysql 目录以及其他文件。此时mysql自身已经初始化完成了,不过现在mysql还不是服务的形式,不能使用service xxx start 的方式启动。但可以使用./bin/mysqld_safe & 的方式启动
注:手动启动mysql 的命令:./bin/mysqld_safe & #至于为什么使用mysqld_safe,自己可以查下原因。
手动停止mysql的命令:./bin/mysqladmin –h127.0.0.1 shutdown #注意,尽量不要使用localhost,因为有时由于系统的原因,使用localhost会提示无法连接mysql。
手动停止mysql的第二种命令:pkill mysql #杀死所有名称中包含mysql的进程,干净利落 :-D
其他linux下mysql实用命令我后边会附带些。
【注册mysql为系统服务】
如果希望mysql以服务的方式启动,或者设置mysql开机启动,还需要如下步骤。
将support-files 中的mysql.server 拷贝到 /etc/rc.d/init.d/ 下,并重名为mysql (如果你不嫌mysql.server这个名字比较长的话,可以不重命名:-D ,文件名就是服务的名字)。
这是就可以使用service mysql start 来启动mysql了(如果在上一步中你不小心手动启动了mysql,这一步会提示mysql已经启动)。
当然,相应的其他命令还有 service mysql stop/restart/status 等
【设置mysql 开机启动】
此时mysql已经注册为服务了,如需开机启动,再需要两步操作。
首先将mysql加入开机启动列表:
chkconfig --add mysql
然后设置它开机启动:
chkconfig mysql on
这样mysql就会开机启动了。
如果需要关闭开机启动,可以:
chkconfig mysql off
查看mysql是否开机启动:
chkconfig --list mysql
查看mysql侦听是否在侦听端口(默认为3306):
netstat -lt | grep mysql
【mysql用户名、远程登录设置】
上面时如何安装及启动mysql,mysql在初次安装后,还需要设置用户名、密码、及远程登录等。
mysql默认情况下,只有root用户,且密码为空,不允许本机以为其他机器登录。如需设置给root设置一个密码,且允许其远程登录,需要这样操作。
首先在mysql安装的机器登录mysql:
mysql -uroot -h127.0.0.1
然后执行如下命令:
grant all privilegeson *.* to root@’%’ identified by ‘12345678’;
如果不需要设置密码,后面的identified by ‘12345678’ 可以省略。
这样,就可以在使用navicat等工具远程连接mysql,进一步执行其他操作了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

LaravelEloquent Model Retrieval: Easily obtaining database data EloquentORM provides a concise and easy-to-understand way to operate the database. This article will introduce various Eloquent model search techniques in detail to help you obtain data from the database efficiently. 1. Get all records. Use the all() method to get all records in the database table: useApp\Models\Post;$posts=Post::all(); This will return a collection. You can access data using foreach loop or other collection methods: foreach($postsas$post){echo$post->

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.
